@@ -297,8 +297,7 @@ impl Settings {
297297
298298 /// This will remove/adjust values in the settings that are not compatible with this version.
299299 pub fn sanitize ( & mut self , version : & Version , language : SolcLanguage ) {
300- const V0_6_0 : Version = Version :: new ( 0 , 6 , 0 ) ;
301- if * version < V0_6_0 {
300+ if * version < Version :: new ( 0 , 6 , 0 ) {
302301 if let Some ( meta) = & mut self . metadata {
303302 // introduced in <https://docs.soliditylang.org/en/v0.6.0/using-the-compiler.html#compiler-api>
304303 // missing in <https://docs.soliditylang.org/en/v0.5.17/using-the-compiler.html#compiler-api>
@@ -308,22 +307,26 @@ impl Settings {
308307 self . debug = None ;
309308 }
310309
311- const V0_7_5 : Version = Version :: new ( 0 , 7 , 5 ) ;
312- if * version < V0_7_5 {
310+ if * version < Version :: new ( 0 , 7 , 5 ) {
313311 // introduced in 0.7.5 <https://github.com/ethereum/solidity/releases/tag/v0.7.5>
314312 self . via_ir = None ;
315313 }
316314
317- const V0_8_7 : Version = Version :: new ( 0 , 8 , 7 ) ;
318- if * version < V0_8_7 {
315+ if * version < Version :: new ( 0 , 8 , 5 ) {
316+ // introduced in 0.8.5 <https://github.com/ethereum/solidity/releases/tag/v0.8.5>
317+ if let Some ( optimizer_details) = & mut self . optimizer . details {
318+ optimizer_details. inliner = None ;
319+ }
320+ }
321+
322+ if * version < Version :: new ( 0 , 8 , 7 ) {
319323 // lower the disable version from 0.8.10 to 0.8.7, due to `divModNoSlacks`,
320324 // `showUnproved` and `solvers` are implemented
321325 // introduced in <https://github.com/ethereum/solidity/releases/tag/v0.8.7>
322326 self . model_checker = None ;
323327 }
324328
325- const V0_8_10 : Version = Version :: new ( 0 , 8 , 10 ) ;
326- if * version < V0_8_10 {
329+ if * version < Version :: new ( 0 , 8 , 10 ) {
327330 if let Some ( debug) = & mut self . debug {
328331 // introduced in <https://docs.soliditylang.org/en/v0.8.10/using-the-compiler.html#compiler-api>
329332 // <https://github.com/ethereum/solidity/releases/tag/v0.8.10>
@@ -336,8 +339,7 @@ impl Settings {
336339 }
337340 }
338341
339- const V0_8_18 : Version = Version :: new ( 0 , 8 , 18 ) ;
340- if * version < V0_8_18 {
342+ if * version < Version :: new ( 0 , 8 , 18 ) {
341343 // introduced in 0.8.18 <https://github.com/ethereum/solidity/releases/tag/v0.8.18>
342344 if let Some ( meta) = & mut self . metadata {
343345 meta. cbor_metadata = None ;
@@ -351,23 +353,26 @@ impl Settings {
351353 }
352354 }
353355
354- if * version < SHANGHAI_SOLC {
356+ if * version < Version :: new ( 0 , 8 , 20 ) {
355357 // introduced in 0.8.20 <https://github.com/ethereum/solidity/releases/tag/v0.8.20>
356358 if let Some ( model_checker) = & mut self . model_checker {
357359 model_checker. show_proved_safe = None ;
358360 model_checker. show_unsupported = None ;
359361 }
360362 }
361363
362- if let Some ( ref mut evm_version) = self . evm_version {
364+ if let Some ( evm_version) = self . evm_version {
363365 self . evm_version = evm_version. normalize_version_solc ( version) ;
364366 }
365367
366- if language == SolcLanguage :: Yul {
367- if !self . remappings . is_empty ( ) {
368- warn ! ( "omitting remappings supplied for the yul sources" ) ;
368+ match language {
369+ SolcLanguage :: Solidity => { }
370+ SolcLanguage :: Yul => {
371+ if !self . remappings . is_empty ( ) {
372+ warn ! ( "omitting remappings supplied for the yul sources" ) ;
373+ }
374+ self . remappings = Vec :: new ( ) ;
369375 }
370- self . remappings = Vec :: new ( ) ;
371376 }
372377 }
373378
@@ -2025,25 +2030,20 @@ mod tests {
20252030
20262031 #[ test]
20272032 fn can_sanitize_byte_code_hash ( ) {
2028- let version: Version = "0.6.0" . parse ( ) . unwrap ( ) ;
2029-
20302033 let settings = Settings { metadata : Some ( BytecodeHash :: Ipfs . into ( ) ) , ..Default :: default ( ) } ;
20312034
20322035 let input =
20332036 SolcInput { language : SolcLanguage :: Solidity , sources : Default :: default ( ) , settings } ;
20342037
2035- let i = input. clone ( ) . sanitized ( & version ) ;
2038+ let i = input. clone ( ) . sanitized ( & Version :: new ( 0 , 6 , 0 ) ) ;
20362039 assert_eq ! ( i. settings. metadata. unwrap( ) . bytecode_hash, Some ( BytecodeHash :: Ipfs ) ) ;
20372040
2038- let version: Version = "0.5.17" . parse ( ) . unwrap ( ) ;
2039- let i = input. sanitized ( & version) ;
2041+ let i = input. sanitized ( & Version :: new ( 0 , 5 , 17 ) ) ;
20402042 assert ! ( i. settings. metadata. unwrap( ) . bytecode_hash. is_none( ) ) ;
20412043 }
20422044
20432045 #[ test]
20442046 fn can_sanitize_cbor_metadata ( ) {
2045- let version: Version = "0.8.18" . parse ( ) . unwrap ( ) ;
2046-
20472047 let settings = Settings {
20482048 metadata : Some ( SettingsMetadata :: new ( BytecodeHash :: Ipfs , true ) ) ,
20492049 ..Default :: default ( )
@@ -2052,7 +2052,7 @@ mod tests {
20522052 let input =
20532053 SolcInput { language : SolcLanguage :: Solidity , sources : Default :: default ( ) , settings } ;
20542054
2055- let i = input. clone ( ) . sanitized ( & version ) ;
2055+ let i = input. clone ( ) . sanitized ( & Version :: new ( 0 , 8 , 18 ) ) ;
20562056 assert_eq ! ( i. settings. metadata. unwrap( ) . cbor_metadata, Some ( true ) ) ;
20572057
20582058 let i = input. sanitized ( & Version :: new ( 0 , 8 , 0 ) ) ;
@@ -2221,4 +2221,19 @@ mod tests {
22212221 let content = fs:: read_to_string ( path) . unwrap ( ) ;
22222222 let _output: CompilerOutput = serde_json:: from_str ( & content) . unwrap ( ) ;
22232223 }
2224+
2225+ // <https://github.com/foundry-rs/foundry/issues/9322>
2226+ #[ test]
2227+ fn can_sanitize_optimizer_inliner ( ) {
2228+ let settings = Settings :: default ( ) . with_via_ir_minimum_optimization ( ) ;
2229+
2230+ let input =
2231+ SolcInput { language : SolcLanguage :: Solidity , sources : Default :: default ( ) , settings } ;
2232+
2233+ let i = input. clone ( ) . sanitized ( & Version :: new ( 0 , 8 , 4 ) ) ;
2234+ assert ! ( i. settings. optimizer. details. unwrap( ) . inliner. is_none( ) ) ;
2235+
2236+ let i = input. sanitized ( & Version :: new ( 0 , 8 , 5 ) ) ;
2237+ assert_eq ! ( i. settings. optimizer. details. unwrap( ) . inliner, Some ( false ) ) ;
2238+ }
22242239}
0 commit comments