Skip to content

Make InstructionTranslator non-copyable - #209

Merged
MaxDesiatov merged 1 commit into
mainfrom
maxd/noncopyable-translator
Jun 18, 2026
Merged

Make InstructionTranslator non-copyable#209
MaxDesiatov merged 1 commit into
mainfrom
maxd/noncopyable-translator

Conversation

@MaxDesiatov

Copy link
Copy Markdown
Member

This avoids unintentional possible ARC traffic if InstructionTranslator is accidentally copied, as it stores references to classes like ISeqAllocator.

@MaxDesiatov
MaxDesiatov force-pushed the maxd/noncopyable-translator branch from a0cd63c to f702339 Compare October 20, 2025 14:05
@MaxDesiatov

Copy link
Copy Markdown
Member Author

Only builds with main snapshots are failing due to an assertion:

SIL memory lifetime failure in @$s7WasmKit21InstructionTranslatorV9allocator19engineConfiguration16funcTypeInterner6module4type6locals13functionIndex8codeSize14isIntercepting0R9DebuggingAcA13ISeqAllocatorC_AA06EngineG0VAA0J0Cy0A5Types08FunctionI0VGAA12EntityHandleVyAA08InstanceZ0VGAVSayAT05ValueI0OGs6UInt32VSiS2btKcfC: memory is not initialized, but should be
memory location:   %25 = struct_element_addr %24 : $*InstructionTranslator, #InstructionTranslator.allocator // user: %26
at instruction:   destroy_addr %171 : $*ISeqAllocator             // id: %172

Abort: function reportError at MemoryLifetimeVerifier.cpp:268
in function:
// InstructionTranslator.init(allocator:engineConfiguration:funcTypeInterner:module:type:locals:functionIndex:codeSize:isIntercepting:isDebugging:)

@kateinoigakukun

Copy link
Copy Markdown
Member

Very concerning that the ASan fuzz detected invalid memory access 🤔 https://github.com/swiftwasm/WasmKit/actions/runs/18654651206/job/53180660404?pr=209

@kateinoigakukun

Copy link
Copy Markdown
Member

If I'm not mistaken, it seems like the SIL code tries to destroy struct members twice when an Error is thrown during the translator init.

// %155                                           // user: %184
bb2(%155 : @owned $any Error):                    // Preds: bb0
  %156 = struct_element_addr %11, #InstructionTranslator.allocator // user: %161
  %157 = struct_element_addr %11, #InstructionTranslator.funcTypeInterner // user: %162
  %158 = struct_element_addr %11, #InstructionTranslator.iseqBuilder // user: %163
  %159 = struct_element_addr %11, #InstructionTranslator.controlStack // user: %164
  %160 = struct_element_addr %11, #InstructionTranslator.type // user: %165
  destroy_addr %156                               // id: %161
  destroy_addr %157                               // id: %162
  destroy_addr %158                               // id: %163
  destroy_addr %159                               // id: %164
  destroy_addr %160                               // id: %165
  debug_value undef : $*InstructionTranslator, var, name "self" // id: %166
  destroy_value %5                                // id: %167
  destroy_value %4                                // id: %168
  destroy_value %2                                // id: %169
  destroy_value %0                                // id: %170
  %171 = struct_element_addr %11, #InstructionTranslator.allocator // user: %172
  destroy_addr %171                               // id: %172
  %173 = struct_element_addr %11, #InstructionTranslator.funcTypeInterner // user: %174
  destroy_addr %173                               // id: %174
  %175 = struct_element_addr %11, #InstructionTranslator.module // user: %176
  destroy_addr %175                               // id: %176
  %177 = struct_element_addr %11, #InstructionTranslator.iseqBuilder // user: %178
  destroy_addr %177                               // id: %178
  %179 = struct_element_addr %11, #InstructionTranslator.controlStack // user: %180
  destroy_addr %179                               // id: %180
  %181 = struct_element_addr %11, #InstructionTranslator.type // user: %182
  destroy_addr %181                               // id: %182
  dealloc_stack %11                               // id: %183
  throw %155                                      // id: %184
} // end sil function 

@MaxDesiatov
MaxDesiatov marked this pull request as draft October 21, 2025 15:28
@MaxDesiatov
MaxDesiatov force-pushed the maxd/noncopyable-translator branch 2 times, most recently from fce1011 to b1539c1 Compare June 17, 2026 11:45
MaxDesiatov added a commit that referenced this pull request Jun 17, 2026
As uncovered by #209 in fuzzing CI jobs, Swift 6.2 and earlier versions miscompile certain uses of `~Copyable`. The miscompile is fixed in 6.3, but we should not be supporting versions where miscompiles can't be fixed. With 6.3 already released and 6.4 branched, bumping to 6.3 lands roughly within the existing declared WasmKit's MSSV policy, depending on when next WasmKit is going to be tagged. If at the time of WasmKit's release Swift 6.4 is not available, temporarily shorter MSSV window is still worth it for avoiding miscompiles.
MaxDesiatov added a commit that referenced this pull request Jun 18, 2026
As uncovered by #209 in fuzzing CI jobs, Swift 6.2 and earlier versions miscompile certain uses of `~Copyable`. The miscompile is fixed in 6.3, but we should not be supporting versions where miscompiles can't be fixed. With 6.3 already released and 6.4 branched, bumping to 6.3 lands roughly within the existing declared WasmKit's MSSV policy, depending on when next WasmKit is going to be tagged. If at the time of WasmKit's release Swift 6.4 is not available, temporarily shorter MSSV window is still worth it for avoiding miscompiles.
@MaxDesiatov
MaxDesiatov force-pushed the maxd/noncopyable-translator branch from b1539c1 to a5c30f5 Compare June 18, 2026 11:38
@MaxDesiatov
MaxDesiatov marked this pull request as ready for review June 18, 2026 11:59
@MaxDesiatov
MaxDesiatov merged commit f7a9934 into main Jun 18, 2026
17 checks passed
@MaxDesiatov
MaxDesiatov deleted the maxd/noncopyable-translator branch June 18, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants