tim: Tim with short hair, smiling, wearing a black jacket over a white T-shirt (Default)
[personal profile] tim
Today: Made what seemed like a multitude of snapshots, but is really just two, to get a series of commits from Erick Tryzelaar, one of our awesome volunteer contributors, integrated before the release happens. The compiler now uses trait-based serialization everywhere!

In the meantime, I looked through my bug list that had been long-neglected while working on release blockers. I realized that #2428, #3521, and #3668 were all connected. In Rust, you can write a variant of an enum type (i.e. algebraic datatype constructor) with an explicit discriminator expression if you want to. An example from the tutorial is:

enum color {
  red = 0xff0000,
  green = 0x00ff00,
  blue = 0x0000ff

This is saying to the compiler that at runtime, the red variant's representation must be the hex numeral 0xff0000, and so on. This feature is sometimes necessary for interacting with foreign code or interacting directly with hardware.

The expression on the right-hand side of the '=' has to be constant: it has to be in a conservative subset of expressions whose meaning can be known at compile-time, without running the program. Explicit numerals, as above, are okay. So are references to compile-time constants:

const red_val: int = 0xff0000;

enum color {
  red = red_val,

Or at least it's supposed to be okay, but it didn't work, because the discriminator expression wasn't getting resolved at all. So you couldn't refer to named constants in it; plus, if you tried to refer to non-constant names (such as local variables) in a discriminator expression, the compiler would crash instead of printing a nice error message.

Anyway, those three bugs were different people noticing the same underlying issue, in different ways. I'm working on it.


tim: Tim with short hair, smiling, wearing a black jacket over a white T-shirt (Default)
Tim Chevalier

October 2017

8910 11121314
15 161718192021

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags