Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comptime variables cannot alias each other #5553

Closed
shawnl opened this issue Jun 7, 2020 · 1 comment
Closed

comptime variables cannot alias each other #5553

shawnl opened this issue Jun 7, 2020 · 1 comment

Comments

@shawnl
Copy link
Contributor

shawnl commented Jun 7, 2020

Because of the internal representation in stage1 and the lack of any memory model at all (I'm not talking about more complicated memory models around concurrency and atomicity), values in comptime cannot be casted at all. This is the root problem of #382 for example.

struct ZigValue {
    ZigType *type;
    ConstValSpecial special;
    uint32_t llvm_align;
    ConstParent parent;
    LLVMValueRef llvm_value;
    LLVMValueRef llvm_global;

    union {
        // populated if special == ConstValSpecialLazy
        LazyValue *x_lazy;

        // populated if special == ConstValSpecialStatic
        BigInt x_bigint;
        BigFloat x_bigfloat;
        float16_t x_f16;
        float x_f32;
        double x_f64;
        float128_t x_f128;
        bool x_bool;
        ConstBoundFnValue x_bound_fn;
        ZigType *x_type;
        ZigValue *x_optional;
        ConstErrValue x_err_union;
        ErrorTableEntry *x_err_set;
        BigInt x_enum_tag;
        ConstStructValue x_struct;
        ConstUnionValue x_union;
        ConstArrayValue x_array;
        ConstPtrValue x_ptr;
        ConstArgTuple x_arg_tuple;
        Buf *x_enum_literal;

        // populated if special == ConstValSpecialStaticRaw
        Buf *dataSlice;

        // populated if special == ConstValSpecialRuntime
        RuntimeHintErrorUnion rh_error_union;
        RuntimeHintOptional rh_maybe;
        RuntimeHintPtr rh_ptr;
        RuntimeHintSlice rh_slice;
    } data;

    // For doing memory actions during comptime
    // if special == ConstValSpecialStaticRaw contain owner of data (if any)
    ZigValue *owner;

    // uncomment this to find bugs. can't leave it uncommented because of a gcc-9 warning
    //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val

    ZigValue(const ZigValue &other) = delete; // plz zero initialize with ZigValue val = {};

    // for use in debuggers
    void dump();
};
@andrewrk
Copy link
Member

andrewrk commented Oct 4, 2020

We have tests that cover this behavior - you need to provide zig code to demonstrate the problem.

@andrewrk andrewrk closed this as completed Oct 4, 2020
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

No branches or pull requests

2 participants