Skip to content

Commit ce228ff

Browse files
authored
Only expose vec_ptype2() at C level (#2126)
* Remove duplicate helper * Add `s3_fallback` arg to C level `vec_ptype2_params()` * Remove some `vec_ptype2_opts()` usages * Simplify `vec_ptype2_from_unspecified()` * Simplify `df_ptype2()` internals * Simplify `df_ptype2()` * Simplify `tib_ptype2()` * Simplify `fct_ptype2()` * Simplify `ord_ptype2()` * Simplify `vec_ptype2_dispatch_native()` * Simplify `vec_ptype2_dispatch_s3()` * Simplify `vec_ptype2_switch_native()` * Only expose C level `vec_ptype2()` * Remove remaining usage of `struct ptype2_opts` * Drop unused `dir` argument * Remove TODO
1 parent 9b6bfcd commit ce228ff

24 files changed

+716
-455
lines changed

R/type2.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ match_from_dispatch <- function(..., `vctrs:::from_dispatch` = FALSE) {
297297
fallback_opts <- function(s3_fallback = NULL) {
298298
# Order is important for the C side
299299
list(
300-
s3_fallback = s3_fallback %||% s3_fallback_default()
300+
s3_fallback = s3_fallback %||% S3_FALLBACK_false
301301
)
302302
}
303303

@@ -363,7 +363,6 @@ vec_ptype2_no_fallback <- function(
363363
)
364364
}
365365

366-
s3_fallback_default <- function() 0L
367366
S3_FALLBACK_false <- 0L
368367
S3_FALLBACK_true <- 1L
369368

src/cast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ r_obj* vec_cast_common(r_obj* xs,
331331
struct r_lazy call) {
332332
return vec_cast_common_params(xs,
333333
to,
334-
S3_FALLBACK_DEFAULT,
334+
S3_FALLBACK_false,
335335
p_arg,
336336
call);
337337
}

src/cast.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ struct cast_opts {
1313
enum s3_fallback s3_fallback;
1414
};
1515

16-
// FIXME: Should we merge these two structs?
17-
static inline
18-
struct ptype2_opts cast_opts_as_ptype2_opts(const struct cast_opts* p_opts) {
19-
return (struct ptype2_opts) {
20-
.x = p_opts->x,
21-
.y = p_opts->to,
22-
.p_x_arg = p_opts->p_x_arg,
23-
.p_y_arg = p_opts->p_to_arg,
24-
.call = p_opts->call,
25-
.s3_fallback = p_opts->s3_fallback,
26-
};
27-
}
28-
2916
struct cast_common_opts {
3017
struct vctrs_arg* p_arg;
3118
struct r_lazy call;

src/decl/ptype2-decl.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
static
2-
r_obj* vec_ptype2_switch_native(const struct ptype2_opts* opts,
3-
enum vctrs_type x_type,
4-
enum vctrs_type y_type,
5-
int* left);
2+
r_obj* vec_ptype2_impl(
3+
r_obj* x,
4+
r_obj* y,
5+
struct vctrs_arg* p_x_arg,
6+
struct vctrs_arg* p_y_arg,
7+
struct r_lazy call,
8+
enum s3_fallback s3_fallback,
9+
int* left,
10+
bool first_pass
11+
);
12+
13+
static
14+
r_obj* vec_ptype2_switch_native(
15+
r_obj* x,
16+
r_obj* y,
17+
enum vctrs_type x_type,
18+
enum vctrs_type y_type,
19+
struct vctrs_arg* p_x_arg,
20+
struct vctrs_arg* p_y_arg,
21+
struct r_lazy call,
22+
enum s3_fallback s3_fallback,
23+
int* left
24+
);

src/decl/type-data-frame-decl.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,27 @@ static
3333
void init_bare_data_frame(r_obj* x, r_ssize n);
3434

3535
static
36-
r_obj* df_ptype2_match(const struct ptype2_opts* opts,
37-
r_obj* x_names,
38-
r_obj* y_names);
36+
r_obj* df_ptype2_match(
37+
r_obj* x,
38+
r_obj* y,
39+
r_obj* x_names,
40+
r_obj* y_names,
41+
struct vctrs_arg* p_x_arg,
42+
struct vctrs_arg* p_y_arg,
43+
struct r_lazy call,
44+
enum s3_fallback s3_fallback
45+
);
3946

4047
static
41-
r_obj* df_ptype2_loop(const struct ptype2_opts* opts,
42-
r_obj* y_names);
48+
r_obj* df_ptype2_loop(
49+
r_obj* x,
50+
r_obj* y,
51+
r_obj* names,
52+
struct vctrs_arg* p_x_arg,
53+
struct vctrs_arg* p_y_arg,
54+
struct r_lazy call,
55+
enum s3_fallback s3_fallback
56+
);
4357

4458
static
4559
r_obj* df_cast_match(const struct cast_opts* opts,

src/dictionary.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,13 @@ SEXP vec_match_params(SEXP needles,
398398
int nprot = 0;
399399

400400
int _;
401-
SEXP type = vec_ptype2_params(
401+
SEXP type = vec_ptype2(
402402
needles,
403403
haystack,
404404
needles_arg,
405405
haystack_arg,
406406
call,
407+
S3_FALLBACK_false,
407408
&_
408409
);
409410
PROTECT_N(type, &nprot);
@@ -573,12 +574,13 @@ SEXP vec_in(
573574
int nprot = 0;
574575

575576
int _;
576-
SEXP type = vec_ptype2_params(
577+
SEXP type = vec_ptype2(
577578
needles,
578579
haystack,
579580
p_needles_arg,
580581
p_haystack_arg,
581582
call,
583+
S3_FALLBACK_false,
582584
&_
583585
);
584586
PROTECT_N(type, &nprot);

src/if-else.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,13 @@ r_obj* ptype_finalize(
550550
// Common type of `true` and `false`
551551
int left;
552552
ptype = KEEP_N(
553-
vec_ptype2_params(
553+
vec_ptype2(
554554
true_,
555555
false_,
556556
p_true_arg,
557557
p_false_arg,
558558
error_call,
559+
S3_FALLBACK_false,
559560
&left
560561
),
561562
&n_prot
@@ -576,12 +577,13 @@ r_obj* ptype_finalize(
576577
}
577578

578579
ptype = KEEP_N(
579-
vec_ptype2_params(
580+
vec_ptype2(
580581
ptype,
581582
missing,
582583
p_ptype_arg,
583584
p_missing_arg,
584585
error_call,
586+
S3_FALLBACK_false,
585587
&left
586588
),
587589
&n_prot

src/interval.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ r_obj* vec_interval_group_info(r_obj* start,
7373
int n_prot = 0;
7474

7575
int _;
76-
r_obj* ptype = vec_ptype2_params(
76+
r_obj* ptype = vec_ptype2(
7777
start,
7878
end,
7979
args_start,
8080
args_end,
8181
r_lazy_null,
82+
S3_FALLBACK_false,
8283
&_
8384
);
8485
KEEP_N(ptype, &n_prot);
@@ -316,12 +317,13 @@ r_obj* vec_interval_complement(r_obj* start,
316317
int n_prot = 0;
317318

318319
int _;
319-
r_obj* ptype = vec_ptype2_params(
320+
r_obj* ptype = vec_ptype2(
320321
start,
321322
end,
322323
args_start,
323324
args_end,
324325
r_lazy_null,
326+
S3_FALLBACK_false,
325327
&_
326328
);
327329
KEEP_N(ptype, &n_prot);
@@ -726,12 +728,13 @@ r_obj* vec_interval_locate_containers(r_obj* start, r_obj* end) {
726728
int n_prot = 0;
727729

728730
int _;
729-
r_obj* ptype = vec_ptype2_params(
731+
r_obj* ptype = vec_ptype2(
730732
start,
731733
end,
732734
args_start,
733735
args_end,
734736
r_lazy_null,
737+
S3_FALLBACK_false,
735738
&_
736739
);
737740
KEEP_N(ptype, &n_prot);

src/list-combine.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,16 +1816,16 @@ r_obj* ptype_common_with_default(
18161816

18171817
// Now incorporate `default` and `p_default_arg` if required
18181818
if (has_default) {
1819-
const struct ptype2_opts ptype2_opts = {
1820-
.x = ptype,
1821-
.y = default_,
1822-
.p_x_arg = vec_args.empty,
1823-
.p_y_arg = p_default_arg,
1824-
.call = error_call,
1825-
.s3_fallback = s3_fallback
1826-
};
18271819
int _;
1828-
ptype = vec_ptype2_opts(&ptype2_opts, &_);
1820+
ptype = vec_ptype2(
1821+
ptype,
1822+
default_,
1823+
vec_args.empty,
1824+
p_default_arg,
1825+
error_call,
1826+
s3_fallback,
1827+
&_
1828+
);
18291829
}
18301830
KEEP(ptype);
18311831

src/match.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ r_obj* vec_locate_matches(r_obj* needles,
146146
int n_prot = 0;
147147

148148
int _;
149-
r_obj* ptype = KEEP_N(vec_ptype2_params(
149+
r_obj* ptype = KEEP_N(vec_ptype2(
150150
needles,
151151
haystack,
152152
needles_arg,
153153
haystack_arg,
154154
error_call,
155+
S3_FALLBACK_false,
155156
&_
156157
), &n_prot);
157158
ptype = KEEP_N(vec_ptype_finalise(ptype), &n_prot);

0 commit comments

Comments
 (0)