Closed Bug 327896 Opened 20 years ago Closed 20 years ago

JS_STATIC_ASSERT to assert during compilation

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: igor, Assigned: igor)

References

Details

Attachments

(1 file, 3 obsolete files)

In few places SpiderMonkey's code use JS_ASSERT(compiler_time_constant_condition). It would be nice to replace them by truly compiler time asserts that are always on and trigger compilation errors when violated.
Attached patch Implementation (obsolete) — — Splinter Review
The patch adds JS_COMPILER_ASSERT to jsutil.h and uses it in jsbit.h/jsgc.c. Does it compiles with Visual C without any warnings about unused typedefs?
Assignee: general → igor.bukanov
Status: NEW → ASSIGNED
Attachment #212453 - Flags: review?(brendan)
Ah, good, your ASSERT -> ASSERT_IMPL -> ASSERT_IMPL2 trick here makes __LINE__ actually become the number. For the macro args, perhaps _condition and _line would be a bit safer?
Attached patch Implementation v2 (obsolete) — — Splinter Review
Extending the patch to asserts about ATOM_INDEX_LIMIT_LOG2 and JSTYPE_LIMIT
Attachment #212453 - Attachment is obsolete: true
Attachment #212476 - Flags: review?(brendan)
Attachment #212453 - Flags: review?(brendan)
Attached patch Implementation v3 (obsolete) — — Splinter Review
This version removes changes to jsbit.h: I will add them to the patch from bug 327129.
Attachment #212476 - Attachment is obsolete: true
Attachment #212478 - Flags: review?(brendan)
Attachment #212476 - Flags: review?(brendan)
(In reply to comment #2) > Ah, good, your ASSERT -> ASSERT_IMPL -> ASSERT_IMPL2 trick here makes __LINE__ > actually become the number. For the macro args, perhaps _condition and _line > would be a bit safer? I am curious why _line would be safer?
Blocks: 327129
Comment on attachment 212478 [details] [diff] [review] Implementation v3 Cool. One thought: JS_STATIC_ASSERT might be slightly clearer (JS_COMPILER could mean something to-do with the SpiderMonkey bytecode compiler). /be
Attachment #212478 - Flags: review?(brendan) → review+
I committed the last patch
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Summary: Compiler-time asserts → JS_STATIC_ASSERT to assert during compilation
Flags: testcase-
A static assertion macro based on this one is being added to NSPR in bug 375985 :)
Depends on: 381236
This caused bug 381236.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: