@@ -38,7 +38,6 @@ export interface IndexAccessGeneratorContext {
3838 ensureDouble ( value : string ) : string ;
3939 setUsesJson ( value : boolean ) : void ;
4040 emitError ( message : string , loc ?: SourceLocation , suggestion ?: string ) : never ;
41- isSafeIndex ( indexName : string , arrayName : string ) : boolean ;
4241}
4342
4443/**
@@ -182,19 +181,6 @@ export class IndexAccessGenerator {
182181 return indexValue ;
183182 }
184183
185- // Returns true when the given index access is a direct `arr[i]` pattern where
186- // the (i, arr) pair has been proven safe by loop analysis, so we can skip the
187- // runtime bounds check entirely.
188- private isProvenSafeAccess ( expr : IndexAccessNode | IndexAccessAssignmentNode ) : boolean {
189- const obj = expr . object as ExprBase ;
190- const idx = expr . index as ExprBase ;
191- if ( obj . type !== "variable" ) return false ;
192- if ( idx . type !== "variable" ) return false ;
193- const arrName = ( expr . object as VariableNode ) . name ;
194- const idxName = ( expr . index as VariableNode ) . name ;
195- return this . ctx . isSafeIndex ( idxName , arrName ) ;
196- }
197-
198184 private emitBoundsCheck ( arrayPtr : string , arrayType : string , index : string ) : void {
199185 const lenPtr = this . ctx . nextTemp ( ) ;
200186 this . ctx . emit (
@@ -232,9 +218,7 @@ export class IndexAccessGenerator {
232218 stringArrayPtr = cast ;
233219 }
234220
235- if ( ! this . isProvenSafeAccess ( expr ) ) {
236- this . emitBoundsCheck ( stringArrayPtr , "%StringArray" , index ) ;
237- }
221+ this . emitBoundsCheck ( stringArrayPtr , "%StringArray" , index ) ;
238222
239223 const dataPtr = this . ctx . nextTemp ( ) ;
240224 this . ctx . emit (
@@ -265,9 +249,7 @@ export class IndexAccessGenerator {
265249 arrayPtr = cast ;
266250 }
267251
268- if ( ! this . isProvenSafeAccess ( expr ) ) {
269- this . emitBoundsCheck ( arrayPtr , "%Array" , index ) ;
270- }
252+ this . emitBoundsCheck ( arrayPtr , "%Array" , index ) ;
271253
272254 const dataPtr = this . ctx . nextTemp ( ) ;
273255 this . ctx . emit ( `${ dataPtr } = getelementptr inbounds %Array, %Array* ${ arrayPtr } , i32 0, i32 0` ) ;
@@ -334,10 +316,9 @@ export class IndexAccessGenerator {
334316 const index = this . toI32Index ( indexDouble ) ;
335317 const contiguousStride = this . getContiguousStride ( expr ) ;
336318
337- const safeAccess = this . isProvenSafeAccess ( expr ) ;
338319 const arrayType = this . ctx . getVariableType ( arrayPtr ) ;
339320 if ( arrayType === "%ObjectArray*" ) {
340- if ( ! safeAccess ) this . emitBoundsCheck ( arrayPtr , "%ObjectArray" , index ) ;
321+ this . emitBoundsCheck ( arrayPtr , "%ObjectArray" , index ) ;
341322 if ( contiguousStride > 0 ) {
342323 return this . emitContiguousElementPtr ( arrayPtr , "%ObjectArray" , index , contiguousStride ) ;
343324 }
@@ -353,7 +334,7 @@ export class IndexAccessGenerator {
353334 if ( arrayType === "i8*" ) {
354335 const arrayCast = this . ctx . nextTemp ( ) ;
355336 this . ctx . emit ( `${ arrayCast } = bitcast i8* ${ arrayPtr } to %ObjectArray*` ) ;
356- if ( ! safeAccess ) this . emitBoundsCheck ( arrayCast , "%ObjectArray" , index ) ;
337+ this . emitBoundsCheck ( arrayCast , "%ObjectArray" , index ) ;
357338 if ( contiguousStride > 0 ) {
358339 return this . emitContiguousElementPtr ( arrayCast , "%ObjectArray" , index , contiguousStride ) ;
359340 }
@@ -366,7 +347,7 @@ export class IndexAccessGenerator {
366347 return this . emitPointerArrayElementPtr ( data , index ) ;
367348 }
368349
369- if ( ! safeAccess ) this . emitBoundsCheck ( arrayPtr , "%ObjectArray" , index ) ;
350+ this . emitBoundsCheck ( arrayPtr , "%ObjectArray" , index ) ;
370351 if ( contiguousStride > 0 ) {
371352 return this . emitContiguousElementPtr ( arrayPtr , "%ObjectArray" , index , contiguousStride ) ;
372353 }
@@ -385,9 +366,7 @@ export class IndexAccessGenerator {
385366
386367 const index = this . toI32Index ( indexDouble ) ;
387368
388- if ( ! this . isProvenSafeAccess ( expr ) ) {
389- this . emitBoundsCheck ( arrayPtr , "%Uint8Array" , index ) ;
390- }
369+ this . emitBoundsCheck ( arrayPtr , "%Uint8Array" , index ) ;
391370
392371 const dataFieldPtr = this . ctx . nextTemp ( ) ;
393372 this . ctx . emit (
0 commit comments