fix(sema): reject target gated builtin methods on wrong target#1890
fix(sema): reject target gated builtin methods on wrong target#1890aryanbaranwal001 wants to merge 2 commits into
Conversation
Signed-off-by: Aryan Baranwal <aryanbaranwal131214@gmail.com>
|
The CI failures are unrelated to this change.
And runs all cargo invocations ( The full transitive chain that pulls ruint is ( ❯ cargo tree --invert --package ruint
ruint v1.17.2
└── alloy-primitives v0.7.7
├── solang-forge-fmt v0.2.0 (/solang/fmt)
└── solang-forge-fmt v0.2.0
└── solang v0.3.4 (/solang)This PR makes no changes to any dependency. The same failure will affect the next scheduled CI run on Possible fixes:
Happy to open a separate PR for whichever fix is preferred. Though I suggest bumping up the toolchain to |
This PR fixes compiler panics caused by calling target gated builtin methods on a target they are not valid for
Option::unwrap()onextendTtlwhen compiled for a non-Soroban target #1872Each builtin in
BUILTIN_METHODScarries atargetfield, empty means available on all targets, non empty means restricted to the listed targets only. Theis_builtin_callatsrc/sema/builtin.rs:898already enforces this withp.target.is_empty() || p.target.contains(&ns.target). The method resolver atsrc/sema/builtin.rs:1446filters only by name and receiver type and never checksfunc.target. So any target gated builtin method passes sema on every target and reaches codegen, where the target specific host function lookup fails and the compiler panics.extendTtlis gated to Soroban but sema accepted it on Solana, Polkadot, and EVM, causing.unwrap()to panic atcodegen/expression.rs:2892.Fix
Add the target check to the filter at
src/sema/builtin.rs:1446:And improve the
funcs.is_empty()branch atsrc/sema/builtin.rs:1525to emit a specific diagnostic when the method exists but is gated to a different target:Now any target gated builtin method called on the wrong target is rejected in sema with a clear diagnostic instead of panicking in codegen. Methods with no target restriction are unaffected.
Happy to make changes if the approach needs adjustment.