Skip to content

Commit

Permalink
function types carry access information
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Nov 27, 2023
1 parent 1f9ce66 commit 6bcad92
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 1 deletion.
1 change: 1 addition & 0 deletions runtime/convertValues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func TestRuntimeExportValue(t *testing.T) {
testFunction := &interpreter.InterpretedFunctionValue{
Type: sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
sema.UnauthorizedAccess,
nil,
sema.VoidTypeAnnotation,
),
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3566,6 +3566,7 @@ func functionTypeFunction(invocation Invocation) Value {
interpreter,
sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
sema.UnauthorizedAccess,
parameterTypes,
sema.NewTypeAnnotation(returnType),
),
Expand Down
2 changes: 2 additions & 0 deletions runtime/interpreter/value_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestFunctionStaticType(t *testing.T) {

hostFunctionType := sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
sema.UnauthorizedAccess,
nil,
sema.BoolTypeAnnotation,
)
Expand All @@ -71,6 +72,7 @@ func TestFunctionStaticType(t *testing.T) {

hostFunctionType := sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
sema.UnauthorizedAccess,
nil,
sema.BoolTypeAnnotation,
)
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,7 @@ func TestValue_ConformsToStaticType(t *testing.T) {

functionType := sema.NewSimpleFunctionType(
sema.FunctionPurityImpure,
sema.UnauthorizedAccess,
[]sema.Parameter{
{
TypeAnnotation: sema.IntTypeAnnotation,
Expand Down
3 changes: 3 additions & 0 deletions runtime/sema/check_composite_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,11 +1292,13 @@ func (checker *Checker) checkCompositeLikeConformance(

initializerType := NewSimpleFunctionType(
compositeType.ConstructorPurity,
UnauthorizedAccess,
compositeType.ConstructorParameters,
VoidTypeAnnotation,
)
interfaceInitializerType := NewSimpleFunctionType(
conformance.InitializerPurity,
UnauthorizedAccess,
conformance.InitializerParameters,
VoidTypeAnnotation,
)
Expand Down Expand Up @@ -2192,6 +2194,7 @@ func (checker *Checker) checkSpecialFunction(

functionType := NewSimpleFunctionType(
purity,
fnAccess,
parameters,
VoidTypeAnnotation,
)
Expand Down
2 changes: 2 additions & 0 deletions runtime/sema/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var _ ast.ExpressionVisitor[Type] = &Checker{}

var baseFunctionType = NewSimpleFunctionType(
FunctionPurityImpure,
UnauthorizedAccess,
nil,
VoidTypeAnnotation,
)
Expand Down Expand Up @@ -1128,6 +1129,7 @@ func (checker *Checker) convertFunctionType(t *ast.FunctionType) Type {

return NewSimpleFunctionType(
purity,
UnauthorizedAccess,
parameters,
returnTypeAnnotation,
)
Expand Down
2 changes: 2 additions & 0 deletions runtime/sema/crypto_algorithm_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const HashAlgorithmTypeHashFunctionName = "hash"

var HashAlgorithmTypeHashFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -128,6 +129,7 @@ const HashAlgorithmTypeHashWithTagFunctionName = "hashWithTag"

var HashAlgorithmTypeHashWithTagFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/meta_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var MetaTypeAnnotation = NewTypeAnnotation(MetaType)

var MetaTypeIsSubtypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: "of",
Expand Down
11 changes: 11 additions & 0 deletions runtime/sema/runtime_type_constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type RuntimeTypeConstructor struct {

var MetaTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
nil,
MetaTypeAnnotation,
)
Expand All @@ -34,6 +35,7 @@ const OptionalTypeFunctionName = "OptionalType"

var OptionalTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -48,6 +50,7 @@ const VariableSizedArrayTypeFunctionName = "VariableSizedArrayType"

var VariableSizedArrayTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -62,6 +65,7 @@ const ConstantSizedArrayTypeFunctionName = "ConstantSizedArrayType"

var ConstantSizedArrayTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "type",
Expand All @@ -83,6 +87,7 @@ const DictionaryTypeFunctionName = "DictionaryType"

var DictionaryTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "key",
Expand All @@ -100,6 +105,7 @@ const CompositeTypeFunctionName = "CompositeType"

var CompositeTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -114,6 +120,7 @@ const InterfaceTypeFunctionName = "InterfaceType"

var InterfaceTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -128,6 +135,7 @@ const FunctionTypeFunctionName = "FunctionType"

var FunctionTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "parameters",
Expand All @@ -149,6 +157,7 @@ const IntersectionTypeFunctionName = "IntersectionType"

var IntersectionTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "types",
Expand All @@ -166,6 +175,7 @@ const ReferenceTypeFunctionName = "ReferenceType"

var ReferenceTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "entitlements",
Expand All @@ -187,6 +197,7 @@ const CapabilityTypeFunctionName = "CapabilityType"

var CapabilityTypeFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand Down
11 changes: 11 additions & 0 deletions runtime/sema/string_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func init() {

var StringTypeConcatFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -146,6 +147,7 @@ Returns a new string which contains the given string concatenated to the end of

var StringTypeSliceFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "from",
Expand Down Expand Up @@ -192,6 +194,7 @@ var ByteArrayArrayTypeAnnotation = NewTypeAnnotation(ByteArrayArrayType)

var StringTypeDecodeHexFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
nil,
ByteArrayTypeAnnotation,
)
Expand Down Expand Up @@ -219,6 +222,7 @@ The byte array of the UTF-8 encoding

var StringTypeToLowerFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
nil,
StringTypeAnnotation,
)
Expand All @@ -245,6 +249,7 @@ var StringFunctionType = func() *FunctionType {

functionType := NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
nil,
StringTypeAnnotation,
)
Expand Down Expand Up @@ -302,6 +307,7 @@ var StringFunctionType = func() *FunctionType {

var StringTypeEncodeHexFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -314,6 +320,7 @@ var StringTypeEncodeHexFunctionType = NewSimpleFunctionType(

var StringTypeFromUtf8FunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -330,6 +337,7 @@ var StringTypeFromUtf8FunctionType = NewSimpleFunctionType(

var StringTypeFromCharactersFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -344,6 +352,7 @@ var StringTypeFromCharactersFunctionType = NewSimpleFunctionType(

var StringTypeJoinFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Label: ArgumentLabelNotRequired,
Expand All @@ -362,6 +371,7 @@ var StringTypeJoinFunctionType = NewSimpleFunctionType(

var StringTypeSplitFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "separator",
Expand All @@ -377,6 +387,7 @@ var StringTypeSplitFunctionType = NewSimpleFunctionType(

var StringTypeReplaceAllFunctionType = NewSimpleFunctionType(
FunctionPurityView,
UnauthorizedAccess,
[]Parameter{
{
Identifier: "of",
Expand Down
Loading

0 comments on commit 6bcad92

Please sign in to comment.