Skip to content

Commit

Permalink
add ast-check to ci, fix found bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexu committed Jun 13, 2021
1 parent b9f07b7 commit 7dcc0fb
Show file tree
Hide file tree
Showing 26 changed files with 141 additions and 191 deletions.
1 change: 1 addition & 0 deletions ci/azure/linux_script
Expand Up @@ -61,6 +61,7 @@ make $JOBS install

# look for formatting errors
release/bin/zig fmt --check .. || (echo "Please run 'zig fmt' to fix the non-conforming files listed above." && false)
find . -name "*.zig" ! -path "*/zig-cache/*" ! -path "*/zig-out/*" ! -path "*/build/*" ! -wholename "*/special/compiler_rt.zig" ! -wholename "*/special/compiler_rt/atomics.zig" | xargs -n 1 build/zig ast-check

# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
Expand Down
15 changes: 14 additions & 1 deletion lib/std/fmt/parse_float.zig
Expand Up @@ -34,7 +34,7 @@
// - Only supports round-to-zero
// - Does not handle denormals

const std = @import("../std.zig");
const std = @import("std");
const ascii = std.ascii;

// The mantissa field in FloatRepr is 64bit wide and holds only 19 digits
Expand Down Expand Up @@ -231,6 +231,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .LeadingFractionalZeros;
} else if (c == '_') {
i += 1;
} else {
state = .MantissaIntegral;
}
Expand Down Expand Up @@ -259,6 +261,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == '.') {
i += 1;
state = .MantissaFractional;
} else if (c == '_') {
i += 1;
} else {
state = .MantissaFractional;
}
Expand All @@ -276,13 +280,17 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
} else if (c == 'e' or c == 'E') {
i += 1;
state = .ExponentSign;
} else if (c == '_') {
i += 1;
} else {
state = .ExponentSign;
}
},
.ExponentSign => {
if (c == '+') {
i += 1;
} else if (c == '_') {
return error.InvalidCharacter;
} else if (c == '-') {
negative_exp = true;
i += 1;
Expand All @@ -293,6 +301,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
.LeadingExponentZeros => {
if (c == '0') {
i += 1;
} else if (c == '_') {
i += 1;
} else {
state = .Exponent;
}
Expand All @@ -304,6 +314,8 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
exponent += @intCast(i32, c - '0');
}

i += 1;
} else if (c == '_') {
i += 1;
} else {
return error.InvalidCharacter;
Expand Down Expand Up @@ -405,6 +417,7 @@ test "fmt.parseFloat" {
try expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));

try expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
try expect(approxEqAbs(T, try parseFloat(T, "0_1_2_3_4_5_6.7_8_9_0_0_0e0_0_1_0"), @as(T, 123456.789000e10), epsilon));

if (T != f16) {
try expect(approxEqAbs(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
Expand Down
8 changes: 6 additions & 2 deletions src/AstGen.zig
Expand Up @@ -662,7 +662,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr
const lhs = try expr(gz, scope, .ref, node_datas[node].lhs);
const extra = tree.extraData(node_datas[node].rhs, ast.Node.SliceSentinel);
const start = try expr(gz, scope, .{ .ty = .usize_type }, extra.start);
const end = try expr(gz, scope, .{ .ty = .usize_type }, extra.end);
const end = if (extra.end != 0) try expr(gz, scope, .{ .ty = .usize_type }, extra.end) else .none;
const sentinel = try expr(gz, scope, .{ .ty = .usize_type }, extra.sentinel);
const result = try gz.addPlNode(.slice_sentinel, node, Zir.Inst.SliceSentinel{
.lhs = lhs,
Expand Down Expand Up @@ -3877,6 +3877,10 @@ fn containerDecl(
const node_tags = tree.nodes.items(.tag);
const node_datas = tree.nodes.items(.data);

const prev_fn_block = astgen.fn_block;
astgen.fn_block = null;
defer astgen.fn_block = prev_fn_block;

// We must not create any types until Sema. Here the goal is only to generate
// ZIR for all the field types, alignments, and default value expressions.

Expand Down Expand Up @@ -3976,7 +3980,7 @@ fn containerDecl(
.nonexhaustive_node = nonexhaustive_node,
};
};
if (counts.total_fields == 0) {
if (counts.total_fields == 0 and counts.nonexhaustive_node == 0) {
// One can construct an enum with no tags, and it functions the same as `noreturn`. But
// this is only useful for generic code; when explicitly using `enum {}` syntax, there
// must be at least one tag.
Expand Down
40 changes: 20 additions & 20 deletions src/clang.zig
Expand Up @@ -45,7 +45,7 @@ pub const APValueLValueBase = extern struct {
extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(APValueLValueBase) ?*const Expr;
};

pub const APValueKind = extern enum {
pub const APValueKind = enum(c_int) {
None,
Indeterminate,
Int,
Expand Down Expand Up @@ -105,7 +105,7 @@ pub const APFloat = opaque {
extern fn ZigClangAPFloat_toString(*const APFloat, precision: c_uint, maxPadding: c_uint, truncateZero: bool) [*:0]const u8;
};

pub const APFloatBaseSemantics = extern enum {
pub const APFloatBaseSemantics = enum(c_int) {
IEEEhalf,
BFloat,
IEEEsingle,
Expand Down Expand Up @@ -1037,7 +1037,7 @@ pub const InitListExpr = opaque {
extern fn ZigClangInitListExpr_getInitializedFieldInUnion(*const InitListExpr) ?*FieldDecl;
};

pub const BO = extern enum {
pub const BO = enum(c_int) {
PtrMemD,
PtrMemI,
Mul,
Expand Down Expand Up @@ -1073,7 +1073,7 @@ pub const BO = extern enum {
Comma,
};

pub const UO = extern enum {
pub const UO = enum(c_int) {
PostInc,
PostDec,
PreInc,
Expand All @@ -1090,7 +1090,7 @@ pub const UO = extern enum {
Coawait,
};

pub const TypeClass = extern enum {
pub const TypeClass = enum(c_int) {
Adjusted,
Decayed,
ConstantArray,
Expand Down Expand Up @@ -1145,7 +1145,7 @@ pub const TypeClass = extern enum {
ExtVector,
};

const StmtClass = extern enum {
const StmtClass = enum(c_int) {
NoStmtClass,
GCCAsmStmtClass,
MSAsmStmtClass,
Expand Down Expand Up @@ -1362,7 +1362,7 @@ const StmtClass = extern enum {
WhileStmtClass,
};

pub const CK = extern enum {
pub const CK = enum(c_int) {
Dependent,
BitCast,
LValueBitCast,
Expand Down Expand Up @@ -1429,7 +1429,7 @@ pub const CK = extern enum {
IntToOCLSampler,
};

pub const DeclKind = extern enum {
pub const DeclKind = enum(c_int) {
AccessSpec,
Block,
Captured,
Expand Down Expand Up @@ -1513,7 +1513,7 @@ pub const DeclKind = extern enum {
TranslationUnit,
};

pub const BuiltinTypeKind = extern enum {
pub const BuiltinTypeKind = enum(c_int) {
OCLImage1dRO,
OCLImage1dArrayRO,
OCLImage1dBufferRO,
Expand Down Expand Up @@ -1687,7 +1687,7 @@ pub const BuiltinTypeKind = extern enum {
OMPIterator,
};

pub const CallingConv = extern enum {
pub const CallingConv = enum(c_int) {
C,
X86StdCall,
X86FastCall,
Expand All @@ -1708,7 +1708,7 @@ pub const CallingConv = extern enum {
AArch64VectorCall,
};

pub const StorageClass = extern enum {
pub const StorageClass = enum(c_int) {
None,
Extern,
Static,
Expand All @@ -1717,7 +1717,7 @@ pub const StorageClass = extern enum {
Register,
};

pub const APFloat_roundingMode = extern enum(i8) {
pub const APFloat_roundingMode = enum(i8) {
TowardZero = 0,
NearestTiesToEven = 1,
TowardPositive = 2,
Expand All @@ -1727,29 +1727,29 @@ pub const APFloat_roundingMode = extern enum(i8) {
Invalid = -1,
};

pub const StringLiteral_StringKind = extern enum {
pub const StringLiteral_StringKind = enum(c_int) {
Ascii,
Wide,
UTF8,
UTF16,
UTF32,
};

pub const CharacterLiteral_CharacterKind = extern enum {
pub const CharacterLiteral_CharacterKind = enum(c_int) {
Ascii,
Wide,
UTF8,
UTF16,
UTF32,
};

pub const VarDecl_TLSKind = extern enum {
pub const VarDecl_TLSKind = enum(c_int) {
None,
Static,
Dynamic,
};

pub const ElaboratedTypeKeyword = extern enum {
pub const ElaboratedTypeKeyword = enum(c_int) {
Struct,
Interface,
Union,
Expand All @@ -1759,29 +1759,29 @@ pub const ElaboratedTypeKeyword = extern enum {
None,
};

pub const PreprocessedEntity_EntityKind = extern enum {
pub const PreprocessedEntity_EntityKind = enum(c_int) {
InvalidKind,
MacroExpansionKind,
MacroDefinitionKind,
InclusionDirectiveKind,
};

pub const Expr_ConstantExprKind = extern enum {
pub const Expr_ConstantExprKind = enum(c_int) {
Normal,
NonClassTemplateArgument,
ClassTemplateArgument,
ImmediateInvocation,
};

pub const UnaryExprOrTypeTrait_Kind = extern enum {
pub const UnaryExprOrTypeTrait_Kind = enum(c_int) {
SizeOf,
AlignOf,
VecStep,
OpenMPRequiredSimdAlign,
PreferredAlignOf,
};

pub const OffsetOfNode_Kind = extern enum {
pub const OffsetOfNode_Kind = enum(c_int) {
Array,
Field,
Identifier,
Expand Down
18 changes: 9 additions & 9 deletions src/codegen/llvm/bindings.zig
Expand Up @@ -131,7 +131,7 @@ extern fn LLVMLookupIntrinsicID(Name: [*]const u8, NameLen: usize) c_uint;
pub const disposeMessage = LLVMDisposeMessage;
extern fn LLVMDisposeMessage(Message: [*:0]const u8) void;

pub const VerifierFailureAction = extern enum {
pub const VerifierFailureAction = enum(c_int) {
AbortProcess,
PrintMessage,
ReturnStatus,
Expand Down Expand Up @@ -228,7 +228,7 @@ pub const Builder = opaque {
extern fn LLVMBuildExtractValue(*const Builder, AggVal: *const Value, Index: c_uint, Name: [*:0]const u8) *const Value;
};

pub const IntPredicate = extern enum {
pub const IntPredicate = enum(c_int) {
EQ = 32,
NE = 33,
UGT = 34,
Expand Down Expand Up @@ -274,7 +274,7 @@ pub const TargetMachine = opaque {
) Bool;
};

pub const CodeMode = extern enum {
pub const CodeMode = enum(c_int) {
Default,
JITDefault,
Tiny,
Expand All @@ -284,14 +284,14 @@ pub const CodeMode = extern enum {
Large,
};

pub const CodeGenOptLevel = extern enum {
pub const CodeGenOptLevel = enum(c_int) {
None,
Less,
Default,
Aggressive,
};

pub const RelocMode = extern enum {
pub const RelocMode = enum(c_int) {
Default,
Static,
PIC,
Expand All @@ -301,7 +301,7 @@ pub const RelocMode = extern enum {
ROPI_RWPI,
};

pub const CodeGenFileType = extern enum {
pub const CodeGenFileType = enum(c_int) {
AssemblyFile,
ObjectFile,
};
Expand Down Expand Up @@ -504,7 +504,7 @@ pub const LinkELF = ZigLLDLinkELF;
pub const LinkMachO = ZigLLDLinkMachO;
pub const LinkWasm = ZigLLDLinkWasm;

pub const ObjectFormatType = extern enum(c_int) {
pub const ObjectFormatType = enum(c_int) {
Unknown,
COFF,
ELF,
Expand All @@ -528,7 +528,7 @@ extern fn ZigLLVMWriteArchive(
os_type: OSType,
) bool;

pub const OSType = extern enum(c_int) {
pub const OSType = enum(c_int) {
UnknownOS,
Ananas,
CloudABI,
Expand Down Expand Up @@ -567,7 +567,7 @@ pub const OSType = extern enum(c_int) {
Emscripten,
};

pub const ArchType = extern enum(c_int) {
pub const ArchType = enum(c_int) {
UnknownArch,
arm,
armeb,
Expand Down

0 comments on commit 7dcc0fb

Please sign in to comment.