-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler][ez] Add more Array.prototype methods #30075
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,36 @@ addObject(BUILTIN_SHAPES, BuiltInPropsId, [ | |
|
||
/* Built-in array shape */ | ||
addObject(BUILTIN_SHAPES, BuiltInArrayId, [ | ||
[ | ||
"indexOf", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Read, | ||
returnType: { kind: "Primitive" }, | ||
calleeEffect: Effect.Read, | ||
returnValueKind: ValueKind.Primitive, | ||
}), | ||
], | ||
[ | ||
"includes", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Read, | ||
returnType: { kind: "Primitive" }, | ||
calleeEffect: Effect.Read, | ||
returnValueKind: ValueKind.Primitive, | ||
}), | ||
], | ||
[ | ||
"pop", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: null, | ||
returnType: { kind: "Poly" }, | ||
calleeEffect: Effect.Store, | ||
returnValueKind: ValueKind.Mutable, | ||
}), | ||
], | ||
[ | ||
"at", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
|
@@ -252,6 +282,19 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [ | |
returnValueKind: ValueKind.Primitive, | ||
}), | ||
], | ||
[ | ||
"slice", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Read, | ||
returnType: { | ||
kind: "Object", | ||
shapeId: BuiltInArrayId, | ||
}, | ||
calleeEffect: Effect.Capture, | ||
returnValueKind: ValueKind.Mutable, | ||
}), | ||
], | ||
[ | ||
"map", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
|
@@ -353,7 +396,7 @@ addObject(BUILTIN_SHAPES, BuiltInArrayId, [ | |
"join", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.ConditionallyMutate, | ||
restParam: Effect.Read, | ||
returnType: PRIMITIVE_TYPE, | ||
calleeEffect: Effect.Read, | ||
returnValueKind: ValueKind.Primitive, | ||
|
@@ -478,6 +521,90 @@ addObject(BUILTIN_SHAPES, BuiltInMixedReadonlyId, [ | |
noAlias: true, | ||
}), | ||
], | ||
[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pasted these to Happy to remove these and refactor later if we prefer to not have duplicates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is great! |
||
"concat", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Capture, | ||
returnType: { | ||
kind: "Object", | ||
shapeId: BuiltInArrayId, | ||
}, | ||
calleeEffect: Effect.Capture, | ||
returnValueKind: ValueKind.Mutable, | ||
}), | ||
], | ||
[ | ||
"slice", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Read, | ||
returnType: { | ||
kind: "Object", | ||
shapeId: BuiltInArrayId, | ||
}, | ||
calleeEffect: Effect.Capture, | ||
returnValueKind: ValueKind.Mutable, | ||
}), | ||
], | ||
[ | ||
"every", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.ConditionallyMutate, | ||
returnType: { kind: "Primitive" }, | ||
calleeEffect: Effect.ConditionallyMutate, | ||
returnValueKind: ValueKind.Primitive, | ||
noAlias: true, | ||
mutableOnlyIfOperandsAreMutable: true, | ||
}), | ||
], | ||
[ | ||
"some", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.ConditionallyMutate, | ||
returnType: { kind: "Primitive" }, | ||
calleeEffect: Effect.ConditionallyMutate, | ||
returnValueKind: ValueKind.Primitive, | ||
noAlias: true, | ||
mutableOnlyIfOperandsAreMutable: true, | ||
}), | ||
], | ||
[ | ||
"find", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.ConditionallyMutate, | ||
returnType: { kind: "Poly" }, | ||
calleeEffect: Effect.ConditionallyMutate, | ||
returnValueKind: ValueKind.Mutable, | ||
noAlias: true, | ||
mutableOnlyIfOperandsAreMutable: true, | ||
}), | ||
], | ||
[ | ||
"findIndex", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.ConditionallyMutate, | ||
returnType: { kind: "Primitive" }, | ||
calleeEffect: Effect.ConditionallyMutate, | ||
returnValueKind: ValueKind.Primitive, | ||
noAlias: true, | ||
mutableOnlyIfOperandsAreMutable: true, | ||
}), | ||
], | ||
[ | ||
"join", | ||
addFunction(BUILTIN_SHAPES, [], { | ||
positionalParams: [], | ||
restParam: Effect.Read, | ||
returnType: PRIMITIVE_TYPE, | ||
calleeEffect: Effect.Read, | ||
returnValueKind: ValueKind.Primitive, | ||
}), | ||
], | ||
["*", { kind: "Object", shapeId: BuiltInMixedReadonlyId }], | ||
]); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to
push
, we know thatpop
does not perform interior mutability.Effect.Store
here models pop similar toconst arr = []; /*...*/; arr[2] = undefined;
(writing exclusively to the container, not to any internal elements)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever!