Skip to content

Aligning implementation/specification error codes - phase 3 - #1989

Open
Roman-Manevich wants to merge 7 commits into
masterfrom
asl-error-codes-phase-3
Open

Aligning implementation/specification error codes - phase 3#1989
Roman-Manevich wants to merge 7 commits into
masterfrom
asl-error-codes-phase-3

Conversation

@Roman-Manevich

Copy link
Copy Markdown
Collaborator

Distinguish lexical and parse failures

Lexer-detected invalid symbols now use UnknownSymbol and report BE_LE, preserving suggested replacements, while the remaining CannotParse errors report BE_PE.

Classify global-initialization exceptions

Exceptions escaping global initialization now report DE_UE, and build_genv in asl.spec converts the corresponding throwing result to DynamicError(DE_UE).

Classify asserted-type-conversion failures

Failed asserted type conversions now use ATCFailure, reporting DE_TAF during dynamic evaluation and TE_SEF during static evaluation as specified by asl.spec.

Classify repeated tuple-field writes

Repeated fields in tuple assignments now report TE_IAD, matching the specification's use of check_no_duplicates rather than the rework PR's disputed BE_PE mapping.

Distinguish call and tuple arity failures

Static call arity failures now report TE_BC through BadCallArity, while tuple arity failures report TE_UT through BadTupleArity; unchecked runtime arity failures remain uncoded.

@Roman-Manevich Roman-Manevich changed the title Aligning implementation/specification error codes - phase 2 Aligning implementation/specification error codes - phase 3 Sep 4, 2026
@Roman-Manevich
Roman-Manevich marked this pull request as ready for review September 4, 2026 11:42
@Roman-Manevich
Roman-Manevich changed the base branch from master to asl-error-codes-phase-2 September 4, 2026 11:42
@Roman-Manevich
Roman-Manevich force-pushed the asl-error-codes-phase-3 branch 2 times, most recently from 71be2cd to 79d0133 Compare September 4, 2026 14:14
Comment thread asllib/Lexer.mll Outdated
Comment thread asllib/error.ml Outdated
"array@ length@ expression@ %a@ has@ negative@ length:@ %i." pp_expr
e_length length
| MultipleWrites id -> pp_err Parse "multiple@ writes@ to@ %S." id
| MultipleWrites id -> pp_err Typing "multiple@ writes@ to@ %S." id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is reported during AST building (desugaring specifically) - why is it a typing error?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit subtle. AssignableExpressions.tex defines the (AST) desugaring rule by calling check_no_duplicates, which returns a type error. We can roll back to Parse but then there's a discrepancy between the implementation and documentation.
Alternatively, we could change the spec (say, by creating a dedicated duplicates check) so that raises a build error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec needs changing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted Typing back to Parse.
Changed the spec to compare the cardinality of the set of fields with the length of the list and have it emit BE_PE if they differ.

Comment thread asllib/error.ml
Comment on lines 44 to 47
| BadArity of error_handling_time * identifier * int * int
| BadCallArity of { name : identifier; expected : int; provided : int }
| BadTupleArity of { expected : int; actual : int }
| BadParameterArity of error_handling_time * version * identifier * int * int

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the status of BadArity and BadParameterArity after the new Bad{Call,Tuple}Arity? For example, is BadArity an V0-only error, and only used with Dynamic? If so, we should remove error_handling_time from BadArity.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BadArity is used in both ASLv0 and ASLv1 contexts and its error_handling_time depends on the configuration passed to Make in Interpreter.ml so both static/dynamic are possible. The situation is similar with BadParameterArity.

@hrutvik hrutvik Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses of BadArity seem to be:

  • In Interpreter.ml for:
    • incorrect argument/parameter arity for a subprogram call
    • protected_multi_assign
    • run_typed
  • in Native.ml for primitives

From a brief look, these all seem to be for untyped specifications - I believe ASL1 type-checking would catch all of these before interpretation. Am I missing something?

@Roman-Manevich Roman-Manevich Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answered offline.

Comment thread asllib/error.ml
Comment thread asllib/error.ml Outdated
Comment thread asllib/error.ml Outdated
Comment thread asllib/error.ml Outdated
Comment thread asllib/Typing.ml
fatal_from ~loc
@@ Error.BadArity
(Static, name, List.length callee.args, List.length args1)
@@ Error.BadCallArity

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an ASL0-only error site - does it need to change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we support ASL0, this seems like an improvement in terms of the error code and diagnostic message.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASL0 does not have error codes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, this is consistent with the same check for ASLv1. I don't see how this hurts.

Comment thread asllib/error.ml Outdated
Comment thread asllib/error.ml Outdated
Comment thread asllib/Interpreter.ml Outdated
else
fatal_from e1 env (Error.MismatchType (B.debug_value v, [ t.desc ])))
fatal_from e1 env
(Error.ATCFailure (C.error_handling_time, B.debug_value v, t.desc)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have something a bit more flexible than debug_value, ideally a formatter

Probably not for this PR.

Comment thread asllib/error.ml
@@ -42,6 +42,8 @@ type error_desc =
found_call_type : subprogram_type;
}
| BadArity of error_handling_time * identifier * int * int

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is BadArity used for then? Maybe add a little comment to explain this?

@Roman-Manevich Roman-Manevich Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

An arity mismatch detected during evaluation: a subprogram or
          primitive receives the wrong number of arguments, a tuple assignment
          receives the wrong number of values from a subprogram call, or an
          entry point returns the wrong number of values.

?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, what about adding quickly at the start that this should not happen if type-checking worked correctly?

Comment thread asllib/tests/lexer.t


ASL Lexical error (BE_LE): Unknown symbol.
ASL Lexical error (BE_LE): Unknown symbol "".

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's ugly, should we create an issue about this?

Base automatically changed from asl-error-codes-phase-2 to master September 7, 2026 09:12
@Roman-Manevich
Roman-Manevich force-pushed the asl-error-codes-phase-3 branch from 0077e04 to 3ca79fc Compare September 7, 2026 09:12

@HadrienRenaud HadrienRenaud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok to me, but please double check with Hrutvik that he's happy with it

Comment thread asllib/error.ml
Comment on lines +49 to +50
| BadCallArity of { name : identifier; expected : int; provided : int }
| BadTupleArity of { expected : int; actual : int }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a naming mismatch between those 2 declaration: should we use provided or actual?

Comment thread asllib/error.ml
Comment on lines +45 to +48
(** An arity mismatch detected during evaluation: a subprogram or
primitive receives the wrong number of arguments, a tuple assignment
receives the wrong number of values from a subprogram call, or an
entry point returns the wrong number of values. *)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, just a tiny edit:

Suggested change
(** An arity mismatch detected during evaluation: a subprogram or
primitive receives the wrong number of arguments, a tuple assignment
receives the wrong number of values from a subprogram call, or an
entry point returns the wrong number of values. *)
(** [BadArity (time, name, expected, provided)] is raised when there is
an arity mismatch detected during evaluation when it should have been
detected at type-checking: a subprogram or
primitive receives the wrong number of arguments, a tuple assignment
receives the wrong number of values from a subprogram call, or an
entry point returns the wrong number of values. *)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants