Conversation
Every builtin exception class is a value now, all 66 of them, and `raise` works in every form: a class, an instance, an instance held in a variable, and any of those after a `from`. The classes are one indented table in `kohebi-core::error`, so a name and the class it derives from come out of the same row and cannot drift apart, and the hierarchy is there for the `except` that will read it. An `Error` carries the object that was raised as well as its name and its message, boxed, because the case it pays for is a program raising something and the case it must not slow down is division by zero. That is what will make `except ValueError as e` hand back the very instance a `raise e` threw. `SystemExit` is the one class that asks for something rather than reporting something, so it sets the process status and says nothing, and a status is a byte the way the operating system has it. `try` is still missing, so an exception leaves the program rather than being caught by it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #7, the first of two changes for exceptions. This one is the objects and the
raisethat makes them;tryis the next one.What works now
Every builtin exception class is a value bound in
builtins, all 66 of them, verified against a liveBaseException.__subclasses__()walk on CPython 3.14.7. They can be named, called, held in a variable, printed and raised:raiseworks in every form the grammar has: a class, an instance, an instance held in a variable, and any of those followed byfrom. An uncaught one prints the cause chain oldest first with CPython's wording in between, then the last line of the traceback.The hierarchy is one table
A
hierarchy!macro declaresKind,Kind::name,Kind::baseandKind::ALLfrom a single indented table inkohebi-core::error. A name and the class it derives from come out of the same row, so they cannot drift apart, and adding a class is one line.Kind::derives_fromwalks it, which is the questionexceptwill ask in the next PR and the oneisinstanceasks after that.The raised object comes along
Errornow carries the object that was raised, boxed.except ValueError as ehas to hand back the very instance thatraise ethrew, and there is no way back to it from a kind and a message. It is aBoxbecauseErrorsits inside everyResultthe runtime returns: the case being paid for is a program raising something, and the case that must not get slower is dividing by zero.Option<Box<Object>>is 8 bytes, so nothing on the hot path widened.raise e from eis a ring, so the chain walk seeds its seen list with the exception being printed, which is what makes it print once rather than twice. That is what CPython does too.SystemExit
The one class that asks for something rather than reporting something. It sets the process status and prints nothing, and a status is a byte, so 256 exits 0 and -1 exits 255. All 13 argument shapes were diffed against CPython on both output and exit code.
Two documented differences
Attributes are missing, so
e.argsande.__cause__are not readable from Python yet, and the classes that take a specific signature in CPython (OSError,UnicodeDecodeError) take anything positionally here. Both wait on attribute access.raise intstill saysNameErrorrather thanTypeErrorbecauseintis not a builtin yet, andraise ValueError(*args)still refuses because starred call arguments do not lower. Both are pre-existing gaps with their own work.Checked
31 raise programs diffed against CPython 3.14.7, byte-identical apart from the two gaps above.
cargo fmt, the whole workspace test suite, clippy with--all-targets --all-featuresand rustdoc with-D warningsare all clean locally.