Skip to content

Commit ac2fe85

Browse files
authored
* update gnur * Cleanup Remove out-of-sync structs and use gnur's Use Rf_ prefix for all R internals we call Try to deal with the #define eval Rf_eval idiom * some includes and formatting * delete unused files * small refactoring * try sanitizer * missing include * fix perf regression
1 parent 4002968 commit ac2fe85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+334
-596
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"${workspaceFolder}/external/llvm-12.0.0.src/include/**"
1010
],
1111
"defines": [
12-
"ENABLE_SLOWASSERT"
12+
"ENABLE_SLOWASSERT",
13+
"R_NO_REMAP"
1314
],
1415
"cStandard": "c11",
1516
"cppStandard": "c++14",

rir/src/R/Funtab.h

Lines changed: 12 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,136 +2,31 @@
22
#define RIR_FUNTAB_H
33

44
#include "BuiltinIds.h"
5-
65
#include "R/r.h"
76

87
#include <cassert>
98

10-
typedef struct sxpinfo_struct_rjit {
11-
unsigned int type : 5; /* ==> (FUNSXP == 99) %% 2^5 == 3 == CLOSXP
12-
* -> warning: `type' is narrower than values
13-
* of its type
14-
* when SEXPTYPE was an enum */
15-
unsigned int obj : 1;
16-
unsigned int named : 2;
17-
unsigned int gp : 16;
18-
unsigned int mark : 1;
19-
unsigned int debug : 1;
20-
unsigned int trace : 1; /* functions and memory tracing */
21-
unsigned int spare : 1; /* currently unused */
22-
unsigned int gcgen : 1; /* old generation number */
23-
unsigned int gccls : 3; /* node class */
24-
} sxpifo_struct_rjit; /* Tot: 32 */
25-
26-
typedef struct cons_rjit {
27-
SEXP car;
28-
SEXP cdr;
29-
SEXP tag;
30-
} cons_rjit;
31-
32-
typedef struct sexprec_rjit {
33-
struct sxpinfo_struct_rjit sxpinfo;
34-
SEXP attrib;
35-
SEXP gengc_next_node, gengc_prev_node;
36-
union {
37-
struct cons_rjit cons;
38-
int i;
39-
} u;
40-
} sexprec_rjit;
41-
42-
typedef SEXP (*CCODE)(SEXP, SEXP, SEXP, SEXP);
43-
44-
/* Information for Deparsing Expressions */
45-
typedef enum {
46-
PP_INVALID = 0,
47-
PP_ASSIGN = 1,
48-
PP_ASSIGN2 = 2,
49-
PP_BINARY = 3,
50-
PP_BINARY2 = 4,
51-
PP_BREAK = 5,
52-
PP_CURLY = 6,
53-
PP_FOR = 7,
54-
PP_FUNCALL = 8,
55-
PP_FUNCTION = 9,
56-
PP_IF = 10,
57-
PP_NEXT = 11,
58-
PP_PAREN = 12,
59-
PP_RETURN = 13,
60-
PP_SUBASS = 14,
61-
PP_SUBSET = 15,
62-
PP_WHILE = 16,
63-
PP_UNARY = 17,
64-
PP_DOLLAR = 18,
65-
PP_FOREIGN = 19,
66-
PP_REPEAT = 20
67-
} PPkind;
68-
69-
typedef enum {
70-
PREC_FN = 0,
71-
PREC_LEFT = 1,
72-
PREC_EQ = 2,
73-
PREC_RIGHT = 3,
74-
PREC_TILDE = 4,
75-
PREC_OR = 5,
76-
PREC_AND = 6,
77-
PREC_NOT = 7,
78-
PREC_COMPARE = 8,
79-
PREC_SUM = 9,
80-
PREC_PROD = 10,
81-
PREC_PERCENT = 11,
82-
PREC_COLON = 12,
83-
PREC_SIGN = 13,
84-
PREC_POWER = 14,
85-
PREC_DOLLAR = 15,
86-
PREC_NS = 16,
87-
PREC_SUBSET = 17
88-
} PPprec;
9+
static inline int getBuiltinNr(SEXP f) { return f->u.primsxp.offset; }
8910

90-
typedef struct {
91-
PPkind kind; /* deparse kind */
92-
PPprec precedence; /* operator precedence */
93-
unsigned int rightassoc; /* right associative? */
94-
} PPinfo;
95-
96-
/* The type definitions for the table of built-in functions. */
97-
/* This table can be found in ../main/names.c */
98-
typedef struct {
99-
char* name; /* print name */
100-
CCODE cfun; /* c-code address */
101-
int code; /* offset within c-code */
102-
int eval; /* evaluate args? */
103-
int arity; /* function arity */
104-
PPinfo gram; /* pretty-print info */
105-
} FUNTAB;
106-
107-
extern FUNTAB R_FunTab[];
108-
109-
/** Returns us the CCODE object from R_FunTab based on name.
110-
111-
TODO This exists in gnu-r (names.c), when integrated inside, we want to make
112-
use of it.
113-
*/
11411
static inline CCODE getBuiltin(SEXP f) {
115-
int i = ((sexprec_rjit*)f)->u.i;
116-
return R_FunTab[i].cfun;
12+
return R_FunTab[getBuiltinNr(f)].cfun;
11713
}
118-
static inline int getBuiltinNr(SEXP f) { return ((sexprec_rjit*)f)->u.i; }
14+
11915
static inline const char* getBuiltinName(int i) { return R_FunTab[i].name; }
120-
static inline int getBuiltinArity(SEXP f) { return R_FunTab[getBuiltinNr(f)].arity; }
121-
static inline int getFlag(SEXP f) {
122-
int i = ((sexprec_rjit*)f)->u.i;
123-
return (((R_FunTab[i].eval) / 100) % 10);
16+
static inline const char* getBuiltinName(SEXP f) {
17+
return getBuiltinName(getBuiltinNr(f));
12418
}
125-
static inline int getFlag(int i) { return (((R_FunTab[i].eval) / 100) % 10); }
12619

127-
static inline bool builtinUpdatesVisibility(int id) { return getFlag(id) < 2; }
128-
static inline bool builtinVisibility(int id) {
129-
assert(builtinUpdatesVisibility(id));
130-
return getFlag(id) != 1;
20+
static inline int getBuiltinArity(SEXP f) {
21+
return R_FunTab[getBuiltinNr(f)].arity;
13122
}
13223

24+
static inline int getFlag(int i) { return ((R_FunTab[i].eval) / 100) % 10; }
25+
static inline int getFlag(SEXP f) { return getFlag(getBuiltinNr(f)); }
26+
13327
static inline SEXP getBuiltinFun(char const* name) {
134-
assert(R_FunTab[rir::blt(name)].eval % 10 == 1 && "Only use for BUILTINSXP");
28+
assert(R_FunTab[rir::blt(name)].eval % 10 == 1 &&
29+
"Only use for BUILTINSXP");
13530
if (R_FunTab[rir::blt(name)].eval % 100 / 10 == 0)
13631
return Rf_install(name)->u.symsxp.value;
13732
else

rir/src/R/RVector.cpp

Lines changed: 0 additions & 56 deletions
This file was deleted.

rir/src/R/RVector.h

Lines changed: 0 additions & 57 deletions
This file was deleted.

rir/src/R/r.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33

44
#include "common.h"
55

6+
#define R_NO_REMAP
7+
#define USE_RINTERNALS
68
#include <R.h>
9+
#include <R_ext/Print.h>
710
#include <Rinterface.h>
8-
#define USE_RINTERNALS
911
#include <Rinternals.h>
1012

11-
// r print statement
12-
#include <R_ext/Print.h>
13-
14-
#undef error
15-
#undef TRUE
16-
#undef FALSE
17-
#undef length
18-
#undef eval
19-
#undef cons
20-
13+
// Use the function versions (some of the names clash with LLVM)
2114
#undef isNull
22-
inline bool isNull(SEXP s) { return TYPEOF(s) == NILSXP; }
15+
#undef isSymbol
16+
#undef isLogical
17+
#undef isReal
2318
#undef isComplex
24-
inline bool isComplex(SEXP s) { return TYPEOF(s) == CPLXSXP; }
19+
#undef isExpression
20+
#undef isEnvironment
2521
#undef isString
26-
inline bool isString(SEXP s) { return TYPEOF(s) == STRSXP; }
27-
2822
#undef isObject
29-
inline bool isObject(SEXP s) { return OBJECT(s) != 0; }
30-
31-
#undef isVector
32-
23+
inline bool Rf_isNull(SEXP s) { return TYPEOF(s) == NILSXP; }
24+
inline bool Rf_isSymbol(SEXP s) { return TYPEOF(s) == SYMSXP; }
25+
inline bool Rf_isLogical(SEXP s) { return TYPEOF(s) == LGLSXP; }
26+
inline bool Rf_isReal(SEXP s) { return TYPEOF(s) == REALSXP; }
27+
inline bool Rf_isComplex(SEXP s) { return TYPEOF(s) == CPLXSXP; }
28+
inline bool Rf_isExpression(SEXP s) { return TYPEOF(s) == EXPRSXP; }
29+
inline bool Rf_isEnvironment(SEXP s) { return TYPEOF(s) == ENVSXP; }
30+
inline bool Rf_isString(SEXP s) { return TYPEOF(s) == STRSXP; }
31+
inline bool Rf_isObject(SEXP s) { return OBJECT(s) != 0; }
32+
33+
// Clash with LLVM
3334
#undef PI
3435

36+
// Get rid of the macro version of this
37+
#undef R_CheckStack
38+
39+
// Bypass PREXPR from GNU R which causes code objects to be converted to AST
3540
#undef PREXPR
3641
inline SEXP PREXPR(SEXP pr) {
37-
// bypassing PREXPR from Gnur, which causes code objects to be converted to
38-
// AST
3942
SLOWASSERT(TYPEOF(pr) == PROMSXP);
4043
auto res = pr->u.promsxp.expr;
4144
if (TYPEOF(res) == BCODESXP)
@@ -44,10 +47,11 @@ inline SEXP PREXPR(SEXP pr) {
4447
}
4548

4649
extern "C" {
50+
extern FUNTAB R_FunTab[];
4751
extern SEXP R_TrueValue;
4852
extern SEXP R_FalseValue;
4953
extern SEXP R_LogicalNAValue;
50-
};
54+
}
5155

5256
// Performance critical stuff copied from Rinlinedfun.h
5357

@@ -119,5 +123,3 @@ extern int R_PPStackTop;
119123
} while (0)
120124

121125
#endif
122-
123-
#undef R_CheckStack

rir/src/api.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
#include "api.h"
6-
#include "R/Funtab.h"
76
#include "R/Serialize.h"
87
#include "bc/BC.h"
98
#include "bc/Compiler.h"

rir/src/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "R/r.h"
55
#include "compiler/log/debug.h"
66
#include "runtime/Context.h"
7+
78
#include <stdint.h>
89

910
#define REXPORT extern "C"

0 commit comments

Comments
 (0)