Skip to content

Commit 8b65f00

Browse files
[asl reference] added explanations and examples for symbolic evaluability and constrainedness
1 parent 0608f7f commit 8b65f00

6 files changed

Lines changed: 59 additions & 6 deletions

File tree

asllib/doc/SideEffects.tex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,19 @@ \section{Side Effect Sets\label{sec:SideEffectSets}}
158158
See \ExampleRef{Checking Whether Expressions are Symbolically Evaluable}.
159159

160160
\ExampleDef{Why Symbolically Evaluability Matters}
161+
162+
The specification in \listingref{SESIsSymbolicallyEvaluable-bad} is ill-typed.
163+
Specifically, it shows that when an expression is not \symbolicallyevaluableterm{},
164+
it cannot be used to express the type of a bitvector. This is because the value
165+
of the expression might change at runtime.
166+
167+
\ASLListing{Why symbolic evaluability matters}{SESIsSymbolicallyEvaluable-bad}{\typingtests/TypingRule.SESIsSymbolicallyEvaluable.bad.asl}
168+
169+
\ExampleDef{Symbolically Evaluability for Equivalence Testing}
161170
The specification in \listingref{SESIsSymbolicallyEvaluable} is well-typed.
162171
Specifically, it shows how the fact that an expression is \symbolicallyevaluableterm{}
163172
is used to reason about the equivalence of bitwidth expressions.
164-
\ASLListing{Why symbolic evaluability matters}{SESIsSymbolicallyEvaluable}{\typingtests/TypingRule.SESIsSymbolicallyEvaluable.asl}
173+
\ASLListing{Symbolically evaluable expressions}{SESIsSymbolicallyEvaluable}{\typingtests/TypingRule.SESIsSymbolicallyEvaluable.asl}
165174

166175
\RenderProseAndFormally{is_symbolically_evaluable}
167176

asllib/doc/Types.tex

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ \section{Bitvector Types\label{sec:BitvectorTypes}}
539539
The width of a \bitvectortypeterm{} can be either \staticallyevaluableterm{}
540540
or \emph{constrained}. That is, a \symbolicallyevaluableterm{} \constrainedintegerterm{}.
541541

542+
Intuitively, the width of bitvectors need to be \symbolicallyevaluableterm{} in order
543+
to ensure that the types of bitvectors can be statically expressed.
544+
See \ExampleRef{Why Symbolically Evaluability Matters}.
545+
546+
Intuitively, the widths of bitvectors are constrained to help provide an upper bound
547+
on their representations when translating ASL to other languages.
548+
See \ExampleRef{Why Constrained Bitvector Widths Matter}.
549+
542550
\ExampleDef{Symbolic and Constrained Bitwidth}
543551
\listingref{symbolicbitwidth} shows an example of a bitvector whose width
544552
is symbolic --- \verb|2 * N| and a bitvector whose width is determined
@@ -602,8 +610,11 @@ \subsection{Typing Bitvector Types}
602610
In \listingref{typing-tbits}, all the uses of bitvector types are well-typed.
603611
\ASLListing{Well-typed Bitvector types}{typing-tbits}{\typingtests/TypingRule.TBits.asl}
604612

613+
\ExampleDef{Why Constrained Bitvector Widths Matter}
605614
The specification in \listingref{typing-tbits-bad} is ill-typed, since widths need
606615
to be \constrainedintegersterm.
616+
If the requirement for constrained widths were not in place, this subprogram could generate
617+
bitvectors of unbounded width.
607618
\ASLListing{An ill-typed Bitvector type}{typing-tbits-bad}{\typingtests/TypingRule.TBits.bad.asl}
608619

609620
\ExampleRef{A bitvector type with bitfields} shows a well-typed \bitvectortypeterm{} with bitfields.

asllib/doc/dictionary.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ always
8484
ambiguous
8585
among
8686
amongst
87+
amount
8788
an
8889
analysis
8990
analyze
@@ -191,6 +192,8 @@ away
191192
axiom
192193
axiomatically
193194
back
195+
backend
196+
backends
194197
background
195198
backslash
196199
badly
@@ -305,6 +308,7 @@ causes
305308
cell
306309
certain
307310
chance
311+
change
308312
changed
309313
changes
310314
changing
@@ -1301,6 +1305,7 @@ matches
13011305
matching
13021306
material
13031307
mathematical
1308+
matter
13041309
matters
13051310
maximal
13061311
maximum
@@ -2198,6 +2203,7 @@ transitively
21982203
translate
21992204
translated
22002205
translates
2206+
translating
22012207
translation
22022208
transliteration
22032209
traversing
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func returns_bitvector_symbolically_evaluable() => bits(10)
2+
begin
3+
let x : integer{0..10} = 10;
4+
var bv: bits(x) = ARBITRARY: bits(x);
5+
// The type of bv is type bits(x) because x is immutable.
6+
return bv;
7+
end;
8+
9+
func returns_bitvector_not_symbolically_evaluable() => bits(10)
10+
begin
11+
var x : integer{0..10} = 9;
12+
var bv: bits(x) = ARBITRARY: bits(x);
13+
x = 10;
14+
// What is the type of bv here? It's certainly not bits(x).
15+
return bv;
16+
end;
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
func foo(I: integer)
1+
func bitvector_sizes()
22
begin
3-
var R: bits(I); // illegal: I is unconstrained.
3+
var size = ARBITRARY : integer;
4+
let immutable_size = size;
5+
// immutable_size is symbolically evaluable.
6+
// Illegal: immutable_size is not constrained.
7+
var bv: bits(immutable_size);
48
end;

asllib/tests/ASLTypingReference.t/run.t

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ ASL Typing Tests / annotating types:
160160

161161
$ aslref TypingRule.TBits.asl
162162
$ aslref TypingRule.TBits.bad.asl
163-
File TypingRule.TBits.bad.asl, line 3, characters 16 to 17:
164-
var R: bits(I); // illegal: I is unconstrained.
165-
^
163+
File TypingRule.TBits.bad.asl, line 7, characters 17 to 31:
164+
var bv: bits(immutable_size);
165+
^^^^^^^^^^^^^^
166166
ASL Type error: constrained integer expected, provided integer.
167167
[1]
168168
$ aslref TypingRule.TTuple.asl
@@ -1035,6 +1035,13 @@ ASL Typing Tests / annotating types:
10351035
[1]
10361036
$ aslref --no-exec TypingRule.SESForSubprogram.asl
10371037
$ aslref --no-exec TypingRule.SESIsSymbolicallyEvaluable.asl
1038+
$ aslref --no-exec TypingRule.SESIsSymbolicallyEvaluable.bad.asl
1039+
File TypingRule.SESIsSymbolicallyEvaluable.bad.asl, line 12,
1040+
characters 38 to 39:
1041+
var bv: bits(x) = ARBITRARY: bits(x);
1042+
^
1043+
ASL Type error: expected a symbolically evaluable expression/subprogram.
1044+
[1]
10381045
$ aslref TypingRule.SliceEqual.asl
10391046
$ aslref TypingRule.SlicesEqual.asl
10401047
$ aslref TypingRule.BitwidthEqual.asl

0 commit comments

Comments
 (0)