Skip to content

Commit d614ca1

Browse files
committed
explains tyconstantdecl impl
1 parent afc4711 commit d614ca1

File tree

1 file changed

+9
-0
lines changed
  • sway-core/src/decl_engine

1 file changed

+9
-0
lines changed

sway-core/src/decl_engine/id.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ impl SubstTypes for DeclId<TyTraitType> {
240240
}
241241
}
242242

243+
// This implementation deviates from all other DeclId<...> implementations.
244+
// For more, see https://github.com/FuelLabs/sway/pull/7440#discussion_r2428833840.
245+
// A better solution will be implemented in the future.
246+
//
247+
// TL;DR:
248+
// When a constant is declared inside a function, its value is shared by every
249+
// “version” of that function—that is, by all monomorphizations. If we “replace” the
250+
// constant, as other implementations do, we would change its value in *every* version,
251+
// which is incorrect.
243252
impl SubstTypes for DeclId<TyConstantDecl> {
244253
fn subst_inner(&mut self, ctx: &SubstTypesContext) -> HasChanges {
245254
let decl_engine = ctx.engines.de();

0 commit comments

Comments
 (0)