Support alignof and instance_alignof#14087
Support alignof and instance_alignof#14087straight-shoota merged 2 commits intocrystal-lang:masterfrom
alignof and instance_alignof#14087Conversation
|
This will become invalid syntax: def alignof(x)
end
alignof(1)This is a breaking change no matter which Crystal version we release it. I see two ways out:
|
|
There's no feasible way to exclude minor risks of breakage when changing just about anything. If we wanted to avoid accidentally overriding any user-defined features when adding new stuff to the compiler or stdlib, we'd need to take a lot more care and have more frequent major releases to get things out properly. Or we'd need to reserve namespaces for exclusive stdlib use. We don't have any of that and I don't think we need it. In this case, the names are very specific and pretty clearly pointing towards something that you would expect as a compiler feature. I think it's totally fine to proceed with this PR. |
|
The thing about |
|
@HertzDevil Your commitment to BC is applaudable. In this case though I think it's an acceptable risk, given how much effort would be needed to do it "safely" and the low probability of the name clash due to the very technical term. GitHub search shows only 7 files containing that phrase and none of it seem to be problematic (in that sense). |
|
Third way out: allow |
|
I think it's best to avoid the gymnastics to avoid any breakage and let it be. As said, there aren't many occurrences of the word in the wild, so I don't think we need to be that overcautious here. If we get a report we can revert it for 1.11.1 and consider an alternative. |
Resolves part of #14033 (does not include support for members within aggregates).
They are direct analogs of
sizeofandinstance_sizeoffor the most part, so these nodes' implementations should equally be similar in the compiler. The only difference is thatLLVMABIAlignmentOfTypereturns aLibC::UIntrather thanLibC::ULongLongforLLVMABISizeOfType. On the other hand, note thatLLVMAlignOfdoes produce a 64-bit LLVM value likeLLVMSizeOf.