Documentation
¶
Overview ¶
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Copyright Consensys Software Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
SPDX-License-Identifier: Apache-2.0
Index ¶
- func ControlFlow(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError
- func CycleDetection(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError
- func DebugFunctions(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError
- func EntryPoint(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError
- func InlineFunctions(program ast.Program, srcmaps source.Maps[any]) []source.SyntaxError
- func Typing(program ast.Program, field field.Config, srcmaps source.Maps[any]) []source.SyntaxError
- type LVal
- type Stmt
- type Type
- type TypeChecker
- type VariableMap
- type Worklist
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ControlFlow ¶
ControlFlow checks for issues related to the control-flow of a function. For example, where a register is not definitely assigned before being used. Or, a control-flow path exists which is not terminated with ret. This is implemented using a straightforward dataflow analysis. One aspect worth noting is that the dataflow sets hold true for registers which are undefined, and false for registers which are defined.
func CycleDetection ¶
CycleDetection traverses the program and detects cyclic definitions in type constants and aliases.
func DebugFunctions ¶
DebugFunctions checks that every function marked with the #[debug] annotation is safe to elide. Calls to debug functions are dropped entirely during code generation unless verbose mode is enabled (like printf statements), so eliding them must not change the observable state of the program. Specifically, a debug function must not:
(1) declare any return values;
(2) write to a writable memory (i.e. a RAM or write-once memory);
(3) call a function which is not itself marked #[debug].
Observe that (3) is (for now) deliberately conservative: it rejects calls to any non-debug function, even one which cannot access memory. Combined with (1) and (2), this ensures nothing reachable from a debug call can affect the observable state of the program.
func EntryPoint ¶
EntryPoint checks that the program's entry point (the function named "main", if any) is well-formed. The machine boots "main" with a fresh stack frame whose registers are all zero — there is no caller to supply arguments — so any declared parameter would silently read as zero in every execution mode (reference interpreter, bytecode and generated Go alike). Program inputs must instead flow through declared input memories, which are initialised from the supplied inputs at boot time. Hence, an entry point declaring parameters is almost certainly a mistake, and is rejected here.
func InlineFunctions ¶
InlineFunctions checks that every function marked with the #[inline] annotation can actually be inlined at its call sites (and subsequently removed). Specifically, an inlined function must not be:
(1) the entry function "main", since this must remain to boot the machine;
(2) marked #[native], since native functions have no body to inline;
(3) (mutually) recursive with other inlined functions, since inlining such functions can never terminate.
Observe that (3) only rejects recursive cycles consisting entirely of inlined functions. Recursion through a non-inlined function is fine, since the residual call to that function simply remains in the inlined body.
func Typing ¶
Typing validates that each declaration in a program is "correctly typed". For example, the following constant declaration is ill-typed:
constant u8 MAX_U8 = 256
The reason being that the constant's value does not fit in a u8. Likewise, this set of declarations are ill-typed:
public input u8[u8] ROM
function f(val u8) -> (r u10) {
r = ROM + 1
return
}
The problem above is that ROM is an input memory and, hence, ROM+1 does not make sense.
Types ¶
type TypeChecker ¶
type TypeChecker struct {
// contains filtered or unexported fields
}
TypeChecker embodies information needed for type checking a given program.
type VariableMap ¶
VariableMap is a convenient alias.
type Worklist ¶
type Worklist struct {
// contains filtered or unexported fields
}
Worklist encapsulates the notion of a worklist, along with the necessary dataflow sets for a dataflow analysis algorithm.
func NewWorklist ¶
NewWorklist constructs a new worklist of a given capacity.