pure

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

README

hybrid TL1 + TL2 pure kernel

This kernel combines relatively simple TL2 kernel with complicated TL1 kernel.

Primitive types are difficult, because they have different names in TL1/TL2.

And TL1 types are themselves complicated, because they have 2 names - TypeDecl.Name and Construct.Name, ab.t1 = cd.T2, but only if they are not unions, which use Construct.Name only for naming data structure for variant.

Also, TL1 type references can be bare or boxed (explicitly with % sign, or by using lower or upper case).

So, we inveneted those rules:

Kernel has types map element for each possible type reference. For primitives int32 and int are added initially, later if boxed wrapper is declared, Int is also added.

During type resolution, we do not in general normalize, only substitute template arguments. So %int could remain %int.

When we want type canonical string, we always look up each name in types, then normalize reference.

TL2 types normalize into themselves, because TL2 has no boxed references.

Primitives, like int32, int, Int with or without percent sign always normalize to +int32 (boxed) or int32.

Unions always normalize to +Union with explicit boxed sign (TODO - try to run kernel without it).

Bare and boxed references to single-constructor type ab.con = ab.Type; normalize to ab.con or +ab.con.

Then, when language generator wants to construct global names, it can select some strategy to use.

We also explicitly add legacy names to some primitives (int, nat and long), so we generate VectorInt not VectorInt32 in go generator. Later, we'll replace those to TL2 names.

TODO

TL1 template argument/field normalized name collision

modifiers in new kernel

Migration

plan

fields masks - local, external
JSON format - simple types, unions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActualNatArg

type ActualNatArg struct {
	// contains filtered or unexported fields
}

func (*ActualNatArg) FieldIndex

func (arg *ActualNatArg) FieldIndex() int

func (*ActualNatArg) IsField

func (arg *ActualNatArg) IsField() bool

func (*ActualNatArg) IsNatParam

func (arg *ActualNatArg) IsNatParam() bool

func (*ActualNatArg) IsNumber

func (arg *ActualNatArg) IsNumber() bool

func (*ActualNatArg) Name

func (arg *ActualNatArg) Name() string

func (*ActualNatArg) Number

func (arg *ActualNatArg) Number() uint32

type Field

type Field struct {
	// contains filtered or unexported fields
}

func (Field) Bare

func (f Field) Bare() bool

func (Field) BitNumber

func (f Field) BitNumber() uint32

func (Field) CommentBefore

func (f Field) CommentBefore() string

func (Field) CommentRight

func (f Field) CommentRight() string

func (Field) FieldMask

func (f Field) FieldMask() *ActualNatArg

func (Field) IsBit

func (f Field) IsBit() bool

func (Field) MaskTL2Bit

func (f Field) MaskTL2Bit() *int

we do not know if this object is used by some other TL2 object when we generate this, so we return nil if owner does not marked as one needing TL2

func (Field) Name

func (f Field) Name() string

func (Field) NatArgs

func (f Field) NatArgs() []ActualNatArg

func (Field) OwnerTypeInstance

func (f Field) OwnerTypeInstance() TypeInstance

func (Field) TypeInstance

func (f Field) TypeInstance() TypeInstance

type Kernel

type Kernel struct {
	// contains filtered or unexported fields
}

func NewKernel

func NewKernel(opts *OptionsKernel) *Kernel

Add builtin types

func (*Kernel) AddFileTL1

func (k *Kernel) AddFileTL1(file string) error

func (*Kernel) AddFileTL2

func (k *Kernel) AddFileTL2(file string) error

func (*Kernel) AllAnnotations

func (k *Kernel) AllAnnotations() []string

func (*Kernel) AllTypeInstances

func (k *Kernel) AllTypeInstances() []TypeInstance

func (*Kernel) CheckExclamationWrapper

func (k *Kernel) CheckExclamationWrapper(typ *tlast.Combinator) (exclArg *tlast.TemplateArgument, _ []tlast.TemplateArgument, _ error)

exclamation marker is not actually a template at all, "!X" is simply reference to interface RpcFunction, so we remove template argument from the list @any rpcProxy.diagonal {X:Type} query:!X = Vector (Maybe X);

func (*Kernel) Compile

func (k *Kernel) Compile() error

func (*Kernel) CompileBoolTL1

func (k *Kernel) CompileBoolTL1(tlType []*tlast.Combinator) error

func (*Kernel) CompileBuiltinTL1

func (k *Kernel) CompileBuiltinTL1(typ *tlast.Combinator) error

func (*Kernel) CompileTL1

func (k *Kernel) CompileTL1(namespaceTL1SeeHere map[string]*tlast.ParseError) error

func (*Kernel) GetFunctionInstance

func (k *Kernel) GetFunctionInstance(name tlast.TL2TypeName) *TypeInstanceStruct

TODO - remove or fix

func (*Kernel) GetInstance

func (k *Kernel) GetInstance(tr tlast.TL2TypeRef) (TypeInstance, bool, error)

we do not allow creating additional instances externally for now we identify types by TL2TypeRefs/TL2TypeNames, TL1 types are first converted into TL2 style

func (*Kernel) IsDictWrapper

func (k *Kernel) IsDictWrapper(kt *KernelType) (fieldT *KernelType, targs []tlast.TemplateArgument, _ bool)

func (*Kernel) IsDictWrapperResolved

func (k *Kernel) IsDictWrapperResolved(kt *KernelType, resolvedType tlast.TL2TypeRef) (bool, tlast.TL2TypeArgument, tlast.TL2TypeRef, error)

func (*Kernel) IsTrueType

func (k *Kernel) IsTrueType(ktTrue *KernelType) bool

All functions which have empty result => ; will reference true-type instead, if defined

func (*Kernel) IsTrueTypeRef

func (k *Kernel) IsTrueTypeRef(rt tlast.TypeRef) bool

func (*Kernel) IsTrueTypeRef2

func (k *Kernel) IsTrueTypeRef2(rt tlast.TL2TypeRef) bool

func (*Kernel) Migration

func (k *Kernel) Migration() error

Overwrites all files given to kernel. For each dir/file.tl containing combinator in a whitelist, if dir/file.tl2 does not exist, it is created. Then combinator is moved (with conversion) from dir/file.tl into dir/file.tl2 Original file is left, even if it is empty, because user might wish to move remaining comments to the new file.

func (*Kernel) MigrationArgument

func (k *Kernel) MigrationArgument(migrateTips map[*KernelType]struct{}, tip *KernelType,
	tra tlast.TL2TypeArgument, leftArgs []tlast.TemplateArgument, allowRemoved bool) (tlast.TL2TypeArgument, bool, error)

func (*Kernel) MigrationCheckTL2FromTL1Argument

func (k *Kernel) MigrationCheckTL2FromTL1Argument(refErrList *migrationTL1RefsTL2Errors, tra tlast.ArithmeticOrType, migrateTips map[*KernelType]struct{},
	comb *tlast.Combinator, leftArgs []tlast.TemplateArgument) error

func (*Kernel) MigrationCheckTL2FromTL1Field

func (k *Kernel) MigrationCheckTL2FromTL1Field(refErrList *migrationTL1RefsTL2Errors, fieldDef tlast.Field, migrateTips map[*KernelType]struct{},
	comb *tlast.Combinator, leftArgs []tlast.TemplateArgument) error

func (*Kernel) MigrationCheckTL2FromTL1Type

func (k *Kernel) MigrationCheckTL2FromTL1Type(refErrList *migrationTL1RefsTL2Errors, tr tlast.TypeRef, migrateTips map[*KernelType]struct{},
	comb *tlast.Combinator, leftArgs []tlast.TemplateArgument) error

func (*Kernel) MigrationFields

func (k *Kernel) MigrationFields(bb *bytes.Buffer, migrateTips map[*KernelType]struct{}, tip *KernelType, comb *tlast.Combinator,
	fieldsAfterReplace []tlast.Field, typesAfterReplace []tlast.TL2TypeRef, indent bool) ([]tlast.TemplateArgument, error)

func (*Kernel) MigrationForTests

func (k *Kernel) MigrationForTests() (string, error)

migrate and format all files into single deterministic string

func (*Kernel) MigrationTemplateArguments

func (k *Kernel) MigrationTemplateArguments(bb *bytes.Buffer, tip *KernelType, comb *tlast.Combinator) error

func (*Kernel) MigrationTypeRef

func (k *Kernel) MigrationTypeRef(bb *bytes.Buffer, migrateTips map[*KernelType]struct{}, tip *KernelType, comb *tlast.Combinator,
	tr tlast.TL2TypeRef, leftArgs []tlast.TemplateArgument) error

func (*Kernel) MigrationTypeRefImpl

func (k *Kernel) MigrationTypeRefImpl(migrateTips map[*KernelType]struct{}, tip *KernelType,
	tr tlast.TL2TypeRef, leftArgs []tlast.TemplateArgument) (tlast.TL2TypeRef, error)

func (*Kernel) PrintUnusedWarnings

func (k *Kernel) PrintUnusedWarnings()

func (*Kernel) TL1

func (k *Kernel) TL1() []*tlast.Combinator

func (*Kernel) TL2

func (k *Kernel) TL2() []tlast.TL2Combinator

func (*Kernel) TopLevelTypeInstances

func (k *Kernel) TopLevelTypeInstances() []TypeInstance

func (*Kernel) VariantNames

func (k *Kernel) VariantNames(definition []*tlast.Combinator) ([]string, error)

type KernelType

type KernelType struct {
	// contains filtered or unexported fields
}

func (*KernelType) Annotations

func (t *KernelType) Annotations() []string

func (*KernelType) CanBeBare

func (t *KernelType) CanBeBare() bool

func (*KernelType) CanBeBoxed

func (t *KernelType) CanBeBoxed() bool

func (*KernelType) CanonicalName

func (t *KernelType) CanonicalName() tlast.TL2TypeName

func (*KernelType) CombinatorTexts

func (t *KernelType) CombinatorTexts() []string

func (*KernelType) HasAnnotation

func (t *KernelType) HasAnnotation(a string) bool

func (*KernelType) HistoricalName

func (t *KernelType) HistoricalName() tlast.TL2TypeName

func (*KernelType) IsExclamationWrapper

func (t *KernelType) IsExclamationWrapper() bool

Very few functions wrap another function. This is for TL1 only, TL2 does not have this complexity. Currently only PHP generator needs them, because parsing of invokeReq is split between runtime and user code. All other generators should skip/ignore such functions.

func (*KernelType) IsFunction

func (t *KernelType) IsFunction() bool

func (*KernelType) OriginTL2

func (t *KernelType) OriginTL2() bool

func (*KernelType) TL1

func (t *KernelType) TL1() []*tlast.Combinator

We do not want to give generators access to combinators directly. We want every piece of information to come through strict pure public interface.

type KernelTypeTarg

type KernelTypeTarg struct {
	// contains filtered or unexported fields
}

type LocalArg

type LocalArg struct {
	// contains filtered or unexported fields
}

type NameCollision

type NameCollision struct {
	// contains filtered or unexported fields
}

func (*NameCollision) AddSameCaseName

func (c *NameCollision) AddSameCaseName(name string, pr tlast.PositionRange, reason string) error

func (*NameCollision) AddUniqueName

func (c *NameCollision) AddUniqueName(name string, pr tlast.PositionRange, reason string) error

func (*NameCollision) NormalizeName

func (c *NameCollision) NormalizeName(s string) string

func (*NameCollision) ResetNormalized

func (c *NameCollision) ResetNormalized()

allows normalized checks between template arguments and fields, but strict checks between them

type NatFieldUsage

type NatFieldUsage struct {
	UsedAsMask bool

	UsedAsSize bool

	AffectedFields [32]map[*TypeInstanceStruct][]int // bit->type->fieldIndexes
	// contains filtered or unexported fields
}

func (*NatFieldUsage) UsedBits

func (f *NatFieldUsage) UsedBits() []uint32

type OptionsKernel

type OptionsKernel struct {
	WarningsAreErrors bool
	Verbose           bool

	TypesWhiteList string
	TL2WhiteList   string // if !empty, will generate also TL2 factory, meta, etc.

	Annotations string

	RPCPreferTL2WhiteList string // RPC client code will prefer to send requests in TL2 format

	ErrorWriter io.Writer // all Errors and warnings should be redirected to this io.Writer, by default it is os.Stderr

	// This option cannot be set via command line, set by generators which want it.
	// By default, we do not instantiate constants simply to reduce # of created instances.
	InstantiateConstants bool
	// This option cannot be set via command line, set by generators which want it.
	// Most generators skip !X function wrappers, but monolith PHP code uses them,
	InstantiateExclamationWrappers bool

	// TODO - remove after migration code stabilized
	TL2MigrationDevMode bool
	// TODO - quickly adapt new rules, remove these options
	NewBrackets bool // TODO - implement new brackets
}

func (*OptionsKernel) Bind

func (opt *OptionsKernel) Bind(f *flag.FlagSet)

type TypeInstance

type TypeInstance interface {
	CanonicalName() string
	KernelType() *KernelType
	Common() *TypeInstanceCommon

	GoodForMapKey() bool
	IsBit() bool // for vector/tuple special case
	FindCycle(c *cycleFinder, prName tlast.PositionRange)
	GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance
	BoxedOnly() bool

	SkipTL2(r []byte) ([]byte, error)
}

type TypeInstanceArray

type TypeInstanceArray struct {
	TypeInstanceCommon
	// contains filtered or unexported fields
}

func (*TypeInstanceArray) Count

func (ins *TypeInstanceArray) Count() uint32

func (*TypeInstanceArray) DynamicSize

func (ins *TypeInstanceArray) DynamicSize() bool

func (*TypeInstanceArray) Field

func (ins *TypeInstanceArray) Field() Field

func (*TypeInstanceArray) FindCycle

func (ins *TypeInstanceArray) FindCycle(c *cycleFinder, prName tlast.PositionRange)

func (*TypeInstanceArray) GetChildren

func (ins *TypeInstanceArray) GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance

func (*TypeInstanceArray) IsTuple

func (ins *TypeInstanceArray) IsTuple() bool

func (*TypeInstanceArray) SkipTL2

func (ins *TypeInstanceArray) SkipTL2(r []byte) ([]byte, error)

type TypeInstanceCommon

type TypeInstanceCommon struct {
	// contains filtered or unexported fields
}

func (*TypeInstanceCommon) ArgNamespace

func (ins *TypeInstanceCommon) ArgNamespace() string

func (*TypeInstanceCommon) BoxedOnly

func (ins *TypeInstanceCommon) BoxedOnly() bool

func (*TypeInstanceCommon) CanonicalName

func (ins *TypeInstanceCommon) CanonicalName() string

func (*TypeInstanceCommon) CommentBefore

func (ins *TypeInstanceCommon) CommentBefore() string

union has also comment per variant

func (*TypeInstanceCommon) CommentRight

func (ins *TypeInstanceCommon) CommentRight() string

func (*TypeInstanceCommon) Common

func (ins *TypeInstanceCommon) Common() *TypeInstanceCommon

func (*TypeInstanceCommon) GoodForMapKey

func (ins *TypeInstanceCommon) GoodForMapKey() bool

func (*TypeInstanceCommon) HasFetcher

func (ins *TypeInstanceCommon) HasFetcher() bool

func (*TypeInstanceCommon) HasTL2

func (ins *TypeInstanceCommon) HasTL2() bool

func (*TypeInstanceCommon) IsBit

func (ins *TypeInstanceCommon) IsBit() bool

func (*TypeInstanceCommon) IsTopLevel

func (ins *TypeInstanceCommon) IsTopLevel() bool

func (*TypeInstanceCommon) KernelType

func (ins *TypeInstanceCommon) KernelType() *KernelType

func (*TypeInstanceCommon) NatParams

func (ins *TypeInstanceCommon) NatParams() []string

func (*TypeInstanceCommon) OriginTL2

func (ins *TypeInstanceCommon) OriginTL2() bool

func (*TypeInstanceCommon) ResolvedType

func (ins *TypeInstanceCommon) ResolvedType() tlast.TL2TypeRef

func (*TypeInstanceCommon) TLName

func (ins *TypeInstanceCommon) TLName() tlast.TL2TypeName

func (*TypeInstanceCommon) TLTag

func (ins *TypeInstanceCommon) TLTag() uint32

for TL1 union zero, for TL2 union as specified by user for TL1 union variant !zero, for TL2 union variant zero

func (*TypeInstanceCommon) TransformNatArgsToChild

func (w *TypeInstanceCommon) TransformNatArgsToChild(natArgs []ActualNatArg, childNatArgs []ActualNatArg) []ActualNatArg

same code as in func (ins *TypeInstanceStruct) ReplaceUnwrapArgs

type TypeInstanceDict

type TypeInstanceDict struct {
	TypeInstanceCommon
	// contains filtered or unexported fields
}

func (*TypeInstanceDict) Field

func (ins *TypeInstanceDict) Field() Field

func (*TypeInstanceDict) FieldType

func (ins *TypeInstanceDict) FieldType() *TypeInstanceStruct

func (*TypeInstanceDict) FindCycle

func (ins *TypeInstanceDict) FindCycle(c *cycleFinder, prName tlast.PositionRange)

func (*TypeInstanceDict) GetChildren

func (ins *TypeInstanceDict) GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance

func (*TypeInstanceDict) SkipTL2

func (ins *TypeInstanceDict) SkipTL2(r []byte) ([]byte, error)

type TypeInstancePrimitive

type TypeInstancePrimitive struct {
	TypeInstanceCommon
	// contains filtered or unexported fields
}

func (*TypeInstancePrimitive) FindCycle

func (ins *TypeInstancePrimitive) FindCycle(c *cycleFinder, prName tlast.PositionRange)

func (*TypeInstancePrimitive) GetChildren

func (ins *TypeInstancePrimitive) GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance

func (*TypeInstancePrimitive) GoodForMapKey

func (ins *TypeInstancePrimitive) GoodForMapKey() bool

func (*TypeInstancePrimitive) IsBit

func (ins *TypeInstancePrimitive) IsBit() bool

func (*TypeInstancePrimitive) IsTL1Bool

func (ins *TypeInstancePrimitive) IsTL1Bool() (ok bool, falseTag uint32, trueTag uint32)

func (*TypeInstancePrimitive) SkipTL2

func (ins *TypeInstancePrimitive) SkipTL2(r []byte) ([]byte, error)

type TypeInstanceRef

type TypeInstanceRef struct {
	// contains filtered or unexported fields
}

during recursive type resolution, we store pointer to this type, later type instance is instantiated and ins is set

type TypeInstanceStruct

type TypeInstanceStruct struct {
	TypeInstanceCommon
	// contains filtered or unexported fields
}

func (*TypeInstanceStruct) Fields

func (ins *TypeInstanceStruct) Fields() []Field

func (*TypeInstanceStruct) FindCycle

func (ins *TypeInstanceStruct) FindCycle(c *cycleFinder, prName tlast.PositionRange)

func (*TypeInstanceStruct) GetChildren

func (ins *TypeInstanceStruct) GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance

func (*TypeInstanceStruct) GetNatFieldUsage

func (ins *TypeInstanceStruct) GetNatFieldUsage(fieldIndex int, inStructFields bool, inReturnType bool) NatFieldUsage

func (*TypeInstanceStruct) GoodForMapKey

func (ins *TypeInstanceStruct) GoodForMapKey() bool

TODO - check how this works

func (*TypeInstanceStruct) IsAlias

func (ins *TypeInstanceStruct) IsAlias() bool

Both TL1-style typedef (single anonymous field) And actual TL2-style alias. In both cases, there is no TL2 object wrapping around the aliasing type So TL2 serialization format is the same. TL1 format will differ if the first field is Boxed.

func (*TypeInstanceStruct) IsResultAlias

func (ins *TypeInstanceStruct) IsResultAlias() bool

func (*TypeInstanceStruct) IsTypeDef

func (trw *TypeInstanceStruct) IsTypeDef() bool

most generators will need to add !recursive

func (*TypeInstanceStruct) IsTypedef

func (ins *TypeInstanceStruct) IsTypedef() bool

this struct has empty name of the single field (without fieldsmask)

func (*TypeInstanceStruct) IsUnionElement

func (ins *TypeInstanceStruct) IsUnionElement() bool

func (*TypeInstanceStruct) IsUnwrap

func (ins *TypeInstanceStruct) IsUnwrap() bool

Where this type is used during generation, we must instad use wrapped type. vector<int> is compiled into []int.

func (*TypeInstanceStruct) RPCPreferTL2

func (ins *TypeInstanceStruct) RPCPreferTL2() bool

func (*TypeInstanceStruct) ReplaceUnwrapArgs

func (ins *TypeInstanceStruct) ReplaceUnwrapArgs(natArgs []string) []string

same code as in func (w *TypeInstanceCommon) TransformNatArgsToChild

func (*TypeInstanceStruct) ResultNatArgs

func (ins *TypeInstanceStruct) ResultNatArgs() []ActualNatArg

func (*TypeInstanceStruct) ResultType

func (ins *TypeInstanceStruct) ResultType() TypeInstance

func (*TypeInstanceStruct) ResultTypeBare

func (ins *TypeInstanceStruct) ResultTypeBare() bool

In TL1, this is always boxed, but in TL2 references to unions are boxed, and other references are bare

func (*TypeInstanceStruct) SkipTL2

func (ins *TypeInstanceStruct) SkipTL2(r []byte) ([]byte, error)

func (*TypeInstanceStruct) UnionIndex

func (ins *TypeInstanceStruct) UnionIndex() int

zero if not IsUnionElement()

type TypeInstanceUnion

type TypeInstanceUnion struct {
	TypeInstanceCommon
	// contains filtered or unexported fields
}

func (*TypeInstanceUnion) BoxedOnly

func (ins *TypeInstanceUnion) BoxedOnly() bool

func (*TypeInstanceUnion) ElementNatArgs

func (ins *TypeInstanceUnion) ElementNatArgs() []ActualNatArg

func (*TypeInstanceUnion) FindCycle

func (ins *TypeInstanceUnion) FindCycle(c *cycleFinder, prName tlast.PositionRange)

func (*TypeInstanceUnion) GetChildren

func (ins *TypeInstanceUnion) GetChildren(children []TypeInstance, withReturnType bool) []TypeInstance

func (*TypeInstanceUnion) IsEnum

func (ins *TypeInstanceUnion) IsEnum() bool

func (*TypeInstanceUnion) IsUnionMaybe

func (ins *TypeInstanceUnion) IsUnionMaybe() (isMaybe bool, elementField Field)

This is hint to generators

func (*TypeInstanceUnion) SkipTL2

func (ins *TypeInstanceUnion) SkipTL2(r []byte) ([]byte, error)

func (*TypeInstanceUnion) VariantNames

func (ins *TypeInstanceUnion) VariantNames() []string

func (*TypeInstanceUnion) VariantTypes

func (ins *TypeInstanceUnion) VariantTypes() []*TypeInstanceStruct

type Whitelist

type Whitelist struct {
	// contains filtered or unexported fields
}

func NewWhiteList

func NewWhiteList(whiltelistName string, filter string) Whitelist

func (*Whitelist) Empty

func (w *Whitelist) Empty() bool

func (*Whitelist) HasName

func (w *Whitelist) HasName(name tlast.Name) bool

func (*Whitelist) HasName2

func (w *Whitelist) HasName2(name tlast.TL2TypeName) bool

func (*Whitelist) UnusedWarning

func (w *Whitelist) UnusedWarning() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL