@@ -2673,14 +2673,14 @@ function builtin_atomic_cmpxchg(ctx: BuiltinContext): ExpressionRef {
26732673}
26742674builtins . set ( BuiltinNames . atomic_cmpxchg , builtin_atomic_cmpxchg ) ;
26752675
2676- // atomic.wait<T!>(ptr: usize, expected: T, timeout: i64) -> i32
2676+ // atomic.wait<T!>(ptr: usize, expected: T, timeout? : i64) -> i32
26772677function builtin_atomic_wait ( ctx : BuiltinContext ) : ExpressionRef {
26782678 var compiler = ctx . compiler ;
26792679 var module = compiler . module ;
26802680 if (
26812681 checkFeatureEnabled ( ctx , Feature . THREADS ) |
26822682 checkTypeRequired ( ctx ) |
2683- checkArgsRequired ( ctx , 3 )
2683+ checkArgsOptional ( ctx , 2 , 3 )
26842684 ) {
26852685 compiler . currentType = Type . i32 ;
26862686 return module . unreachable ( ) ;
@@ -2690,7 +2690,9 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef {
26902690 var type = typeArguments ! [ 0 ] ;
26912691 var arg0 = compiler . compileExpression ( operands [ 0 ] , compiler . options . usizeType , Constraints . CONV_IMPLICIT ) ;
26922692 var arg1 = compiler . compileExpression ( operands [ 1 ] , type , Constraints . CONV_IMPLICIT ) ;
2693- var arg2 = compiler . compileExpression ( operands [ 2 ] , Type . i64 , Constraints . CONV_IMPLICIT ) ;
2693+ var arg2 = operands . length == 3
2694+ ? compiler . compileExpression ( operands [ 2 ] , Type . i64 , Constraints . CONV_IMPLICIT )
2695+ : module . i64 ( - 1 , - 1 ) ; // Infinite timeout
26942696 compiler . currentType = Type . i32 ;
26952697 switch ( type . kind ) {
26962698 case TypeKind . I32 :
@@ -2708,21 +2710,23 @@ function builtin_atomic_wait(ctx: BuiltinContext): ExpressionRef {
27082710}
27092711builtins . set ( BuiltinNames . atomic_wait , builtin_atomic_wait ) ;
27102712
2711- // atomic.notify(ptr: usize, count: i32) -> i32
2713+ // atomic.notify(ptr: usize, count? : i32) -> i32
27122714function builtin_atomic_notify ( ctx : BuiltinContext ) : ExpressionRef {
27132715 var compiler = ctx . compiler ;
27142716 var module = compiler . module ;
27152717 if (
27162718 checkFeatureEnabled ( ctx , Feature . THREADS ) |
27172719 checkTypeAbsent ( ctx ) |
2718- checkArgsRequired ( ctx , 2 )
2720+ checkArgsOptional ( ctx , 1 , 2 )
27192721 ) {
27202722 compiler . currentType = Type . i32 ;
27212723 return module . unreachable ( ) ;
27222724 }
27232725 var operands = ctx . operands ;
27242726 var arg0 = compiler . compileExpression ( operands [ 0 ] , compiler . options . usizeType , Constraints . CONV_IMPLICIT ) ;
2725- var arg1 = compiler . compileExpression ( operands [ 1 ] , Type . i32 , Constraints . CONV_IMPLICIT ) ;
2727+ var arg1 = operands . length == 2
2728+ ? compiler . compileExpression ( operands [ 1 ] , Type . i32 , Constraints . CONV_IMPLICIT )
2729+ : module . i32 ( - 1 ) ; // Inifinity count of waiters
27262730 compiler . currentType = Type . i32 ;
27272731 return module . atomic_notify ( arg0 , arg1 ) ;
27282732}
0 commit comments